Sql server 使用 in()函数 传递字符串


首先创建一个分隔字符串函数:

 1 create  function  SplitIn(@c   varchar(2000),@split   varchar(2))   
 2 returns   @t   table(col   varchar(20))   
 3 as   
 4 begin    
 5   while(charindex(@split,@c)<>0)   
 6     begin   
 7       insert   @t(col)   values   (substring(@c,1,charindex(@split,@c)-1))   
 8       set   @c   =   stuff(@c,1,charindex(@split,@c),'')   
 9     end   
10   insert   @t(col)   values   (@c)   
11   return   
12 end

第二,在存储过程中使用SplitIn函数

1 select @TeamRoomCount = COUNT(Work_GuestAccount.AccountID)  FROM  Work_GuestAccount INNER JOIN 
2                 Work_GuestEntryIndex ON Work_GuestAccount.EntryID = Work_GuestEntryIndex.EntryID 
3                 WHERE (Work_GuestEntryIndex.TeamID <> '') AND (Work_GuestEntryIndex.TeamID IS NOT NULL)
4                 AND (Work_GuestAccount.RoomID IN (select col from SplitIn(@TeamRoomNo,',')))

转载于:https://my.oschina.net/u/2607133/blog/599007


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM