Author |
Topic |
oceanboy
Starting Member
44 Posts |
Posted - 2007-09-05 : 04:51:26
|
Hi all,Is it possible to write a store procedure that deals with many values? For examplecreate procedure xxx (@list)....select @from tablewhere list in @list......endThanks! |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-05 : 04:53:29
|
yes. But can you give us more detail what do you want to achieve ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
oceanboy
Starting Member
44 Posts |
Posted - 2007-09-05 : 05:01:21
|
khtan,I would like to write a stored procedure that will process at least 1 item. Normally if the SQL only deal with 1 item, we will write it like this:select * from table where list = 1But my plan is to write it so that it will take more than 1 item:select * from table where list in (1,2,3...) |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
oceanboy
Starting Member
44 Posts |
Posted - 2007-09-05 : 05:05:56
|
perhaps I will just use dynamic SQL? |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-05 : 05:09:02
|
select t.*from table as twhere ',' + @list + ',' like '%,' + t.list + ',%' E 12°55'05.25"N 56°04'39.16" |
 |
|
oceanboy
Starting Member
44 Posts |
Posted - 2007-09-05 : 05:26:51
|
what's that Peso? A bit confusing there? Is that an example of the dynamic SQL? |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-05 : 05:43:42
|
No.It is a different way of treating lists the way you want. E 12°55'05.25"N 56°04'39.16" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-09-05 : 06:20:58
|
quote: Originally posted by oceanboy what's that Peso? A bit confusing there? Is that an example of the dynamic SQL?
You need to read sommarskog's artilce for more detailsMadhivananFailing to plan is Planning to fail |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-09-05 : 06:22:07
|
and this is more on dynamic sqlwww.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|