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 2008 Forums
 Transact-SQL (2008)
 Insert with a sort of foreach statement

Author  Topic 

Ciupaz
Posting Yak Master

232 Posts

Posted - 2012-03-05 : 03:35:03
Hello,
I need to write an Update in a stored procedure that has 2 parameters, an ID int value, and a string of comma separated values of ID's, like these:

create stored procedure dbo.InsertAttachedDocumentatation
@IDDoc int
@IDListTypeDoc nvarchar(50)
as

insert dbo.IssueDocAttached(IDIssue, IDTypeDoc)
values
......




and I'd like to call in this way:


EXEC dbo.InsertAttachedDocumentatation 1, '2,5,7,9'

to obtain

1 - 2
1 - 5
1 - 7
1 - 9

in my dbo.IssueDocAttached table.


How can I solve this problem?


Luigi

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-03-05 : 03:49:09
Have a look on to this..

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=171577

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

Ciupaz
Posting Yak Master

232 Posts

Posted - 2012-03-05 : 05:50:36
Thank you Senthil.
Go to Top of Page
   

- Advertisement -