I am new to SQL Server.
I have a form that allows the user to select one or more status values for a project search (The user can search for all projects that are 1> Cancelled 3> Deferred 2> Closed). These selections are passed to my search stored procedure currently as a varchar comma delimited list (1,4,6).
Question 1 => Is a comma delimited list the best way to get the selections into the where clause?
Question 2 => How can I build the appropriate SELECT statement to return the projects given this list of status'?
When I try to supply the list to the where clause manually, the query works.
SELECT * FROM PROJECT WHERE StatusID IN (1,3,2)
When I supply the list ot the WHERE clause via a variable, it fails with a data type error.
DECLARE @ProjStat varchar (10)
SELECT @ProjStat = '1,3,2'
SELECT * FROM PROJECT WHERE StatusID IN (@ProjStat)
I have a form that allows the user to select one or more status values for a project search (The user can search for all projects that are 1> Cancelled 3> Deferred 2> Closed). These selections are passed to my search stored procedure currently as a varchar comma delimited list (1,4,6).
Question 1 => Is a comma delimited list the best way to get the selections into the where clause?
Question 2 => How can I build the appropriate SELECT statement to return the projects given this list of status'?
When I try to supply the list to the where clause manually, the query works.
SELECT * FROM PROJECT WHERE StatusID IN (1,3,2)
When I supply the list ot the WHERE clause via a variable, it fails with a data type error.
DECLARE @ProjStat varchar (10)
SELECT @ProjStat = '1,3,2'
SELECT * FROM PROJECT WHERE StatusID IN (@ProjStat)