sql 存储过程 in 的两种写法


最近又忘记存储过程 除了exec 动态写法的另外一种,这里记录一下,方便查找

写法1,动态语句

 

CREATE PROCEDURE sp_CountShiftWish 
    @strids varchar (1024)   /*strids   是id列表,   类似1,2,3*/ 
AS 
   exec ('select * from student where id in('+@strids+')')
 
go

 

写法2,索引查找

CREATE   PROCEDURE   sp_CountShiftWish 
   @strids   varchar   (1024)   /*strids   是id列表,   类似1,2,3*/ 
AS 
    select   *   from   student   where  charindex(','+ltrim(id)+',',','+@strids+',')>0 
go

 


免责声明!

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



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