asp.net - How to separate (split) string with comma in SQL Server stored procedure -


i have checkboxlist. selected (checked) items stored in list<string> selected.

for example, value selected monday,tuesday,thursday out of 7 days

i converting list<> comma-separated string, i.e.

string a= "monday,tuesday,thursday" 

now, passing value stored procedure string. want fire query like:

select *  tblx  days = 'monday' or days = 'tuesday' or days = 'thursday'` 

my question is: how separate string in stored procedure?

if pass comma separated (any separator) string store procedure , use in query must need spit string , use it.

below have example:

declare @str varchar(500) = 'monday,tuesday,thursday' create table #temp (tday varchar(100)) while len(@str) > 0 begin     declare @tday varchar(100)     if charindex(',',@str) > 0         set  @tday = substring(@str,0,charindex(',',@str))     else         begin         set  @tday = @str         set @str = ''         end   insert  #temp values (@tday)  set @str = replace(@str,@tday + ',' , '')  end   select *   tblx   days in (select tday #temp) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -