2012-12-13 79 views
2

我需要你的手我。使用IN子句在存儲過程中

我在C#.NET 2點窗口的形式,其中第一形式包含所檢查列表框,收集從該框中的值傳遞到第二形式的ID,其中i已寫成這樣

ALTER PROCEDURE [dbo].[sp_GDE_QA] 
@oks_ids varchar(100), 
@Operation varchar(50) 
AS BEGIN 
    declare @Execute as varchar(100) 

    set @Execute = 'select oks_id, path from tb_gde_qc where status=''QC Completed'' and oks_id in '''[email protected]_ids+''''; 

exec(@Execute) 
END 

存儲過程現在我想通過值參數@oks_ids。例如

select oks_id, path 
from tb_gde_qc 
where status=''QC Completed'' 
    and oks_id in ('GD_01358', 'GD_01361', 'GD_01363') 

任何人都可以幫我嗎?將感謝所有

+0

見厄蘭Sommarskog對各種方式的開創性文章[數組和列表在SQL Server 2005及以後(http://www.sommarskog.se/arrays-in-sql-2005.html)在SQL Server 2005處理此 –

回答

0

試試這個

ALTER PROCEDURE [dbo].[sp_GDE_QA] 
@oks_ids varchar(100), 
@Operation varchar(50) 
AS BEGIN 
    declare @Execute as varchar(100) 

    set @Execute = 'select oks_id, path from tb_gde_qc where status=''QC Completed'' and oks_id in '''[email protected]_ids+''''; 

sp_ExecuteSQL @Execute 
END 

sp_executesql的應該能夠處理參數中字符串的傳遞。

我能問在哪裏呢@operation發揮作用?

相關問題