Create procedure [dbo].[sp_Sample] @param1 varchar(100) as DECLARE @Sql VARCHAR(MAX) SET @param1 = REPLACE(@param1,',',''',''') SET @Sql = 'select * from tblSample where col1 IN (''' + @param1 + ''')' Go DECLARE @return_value int EXEC @return_value = [dbo].[sp_Sample] @Escalation = N'SIM4' SELECT 'Return Value' = @return_value GO
当我执行此过程时,什么也不显示
如果有什么问题建议我
谢谢
您没有执行动态查询,请尝试以下操作:
CREATE PROCEDURE [dbo].[sp_Sample] @param1 VARCHAR(100) AS DECLARE @Sql NVARCHAR(MAX) SET @param1 = Replace(@param1, ',', ''',''') SET @Sql = 'select * from tblSample where col1 IN (''' + @param1 + ''')' --PRINT @Sql exec sp_executesql @Sql GO Exec sp_Sample '1001' GO
注意:PRINT语句将打印查询字符串,将其取消注释并检查您的查询。
PRINT