Friday, 6 September 2013

Alternate for split function in case when you pass comma separated Ids in sql


Alternate for split function in case when you pass comma separated Ids in sql



If you have comma separated Ids in code and you want records according to it.So you can't use that string for in condition in query.so last option would be split of Ids string.And if you don't want to split string then one other option is there like :-



  declare @Temp VARCHAR(100);
  set @Temp='1,3,4';


  Select * from CategoryMaster
      where ','+@Temp+',' like '%,'+CAST(CategoryID as varchar)+',%'

No comments:

Post a Comment