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.
Author |
Topic |
PurpleSun
Yak Posting Veteran
50 Posts |
Posted - 2007-02-02 : 09:48:40
|
Hi All,I have a stored proc that accepts two parameters @LocationIDs and @UserNames. @LocationIDs parameter can have single or multiple values, like ', 3, ' or ', 4, 6, 7, '. I can deal with that using: select * from wecarelocations where @LocationIDs like ltrim(('%, ' + cast(LocationCode as varchar(10))) + ',%'). @UserNames parameter also can have single or multiple values, but in different format, like'jdoe' or 'jdoe', 'asmith', sjones'.My question is what should be datatype for @UserNames parameter and how can I parse it.Thanks,Vic |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-02-02 : 11:57:51
|
@UserNames would be a varcharCould be values like'jdoe,asmith,sjones'if you want to allow for embedded commas then'"jdoe","asmith","sjones"'to use it - do the same as beforewhere @UserNames like '"' + UserName @ '"'orwhere ',' + @UserNames + ',' like ',' + UserName @ ','Might be better to create tables of the values passed in and use them - then the query could use indexes.seehttp://www.nigelrivett.net/SQLTsql/ParseCSVString.html==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
PurpleSun
Yak Posting Veteran
50 Posts |
Posted - 2007-02-02 : 12:06:07
|
The problem is that parameter comes from ColdFusion page and I can't get rid of single quotes before and after each coma'jdoe','asmith','sjones'and my SP doesn't accept parameter with this value quote: Originally posted by nr @UserNames would be a varcharCould be values like'jdoe,asmith,sjones'if you want to allow for embedded commas then'"jdoe","asmith","sjones"'to use it - do the same as beforewhere @UserNames like '"' + UserName @ '"'orwhere ',' + @UserNames + ',' like ',' + UserName @ ','Might be better to create tables of the values passed in and use them - then the query could use indexes.seehttp://www.nigelrivett.net/SQLTsql/ParseCSVString.html==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
|
 |
|
|
|
|
|
|