Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to insert (1, 2, 3) as 3 records using SQL

Author  Topic 

liangtp@hotmail.com
Starting Member

27 Posts

Posted - 2008-09-10 : 23:39:15
Hi Guys,

I have a string "1, 2, 3" and when passed to the SQL server to run as :

declare @temp table (
ServiceNo Int)
insert into @temp
select 1, 2, 3

Error occurred. I wish it to be inserted as 3 records. How shall the correct SQL statment look like?

Thanks.

hey001us
Posting Yak Master

185 Posts

Posted - 2008-09-11 : 00:04:11
declare @temp table (
ServiceNo Int)
insert into @temp
select 1 UNION
SELECT 2 UNION
SELECT 3

hey
Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 2008-09-11 : 00:57:20
Hi,

split the records and insert into the table
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 01:23:48
make use of this to split into 3 records and then insert
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTable
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -