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