Thursday, April 18, 2013

Passing string values into SQL query via parameter

CREATE PROC S_Test
(
    @params varchar(100)
)
AS
SET NOCOUNT ON
DECLARE @sql as NVARCHAR(4000)
SET @sql = 'select count(*) from myTable where myColumn in (' + @params + ')'
EXEC sp_ExecuteSQL @sql
GO

No comments:

Post a Comment