|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
insert into vs. select into
can somebody tell me the difference between select into and insert into statements in sql server.
for example: How SELECT LastName,FirstName INTO Student_bk FROM Student is different from INSERT INTO Student_bk(LastName,FirstName) Select (LastName,FirstName) from Student Thanks. |
|
#2
|
||||
|
||||
|
Try running them on a non existent destination table ....
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#3
|
|||
|
|||
|
Thanks for the reply, the confusion i m facing is, in my stored procedure If I have
set @strSql1='SELECT field1 INTO #GetHours from tbl_Hours' + ' WHERE num_Record =' + CONVERT(varchar,@f2) EXEC (@strSql1) WHILE (SELECT COUNT(*) FROM #GetHours)>0 BEGIN ... ... END it gives me an error in Select cout(*) statement, saying "invalid object #GetHours" However, if I change the SQL statement to this, set @strSql1='INSERT INTO #GetHours(field1) ' + ' SELECT field1 FROM tbl_Hours' + ' WHERE ....' it works. The "Select into" statement also works if I don't build a dynanmic string. However, I must build a dynamic string as I still need to add few more "and" clauses depending on the business logic. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > insert into vs. select into |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|