Showing posts with label Passing Comma Seprated List to Store Procedure. Show all posts
Showing posts with label Passing Comma Seprated List to Store Procedure. Show all posts

Thursday, August 21, 2008

Execute sql query with exec or execute and Passing Comma Seprated List of IDs to Store Procedure

Hi,

I was in need to create the query in string variable and execute the same.I found the solution which fits in my situation.

The below mentioned way gives you idea where i need that.As i have the list of values and i want only those records to be retrive from the Database.

EXECUTE(@STRQRY)

ALTER procedure [dbo].[spGetData]
@strDataIDs varchar(max)
as
begin
DECLARE @STRQRY NVARCHAR(MAX)
SET @STRQRY= 'select * from DataMaster where accnum not in (' +@strDataIDs+ ')'
EXECUTE(@STRQRY)
end