MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 4th, 2005, 09:27 AM
cleanice cleanice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 cleanice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 4th, 2005, 09:38 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 15 h 7 m 10 sec
Reputation Power: 279
Try running them on a non existent destination table ....

Reply With Quote
  #3  
Old January 4th, 2005, 10:12 AM
cleanice cleanice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 cleanice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > insert into vs. select into


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT