I have the below scenario:
----------------
ID | Type
----------------
1 | AB
2 | CD
3 | EF
Now, the query I need for this query in stored procedure is:
SELECT * FROM Table_Name WHERE TYPE IN ('AB','CD','EF')
I have written the below procedure:
CREATE PROCEDURE dbo.usp_get_all
@Type VARCHAR(200)
AS
BEGIN
SELECT * FROM Table_Name WHERE TYPE IN (@Type)
END
This query is working fine only when I am calling it in the below way:
EXEC usp_get_all 'AB'
Now, there may be a situation like below, which is not working
EXEC usp_get_all '''AB'',''CD'',''EF'''
My question:
I don't want to use any function to split the comma separated input parameters. Only by using the input parameter I want to get the same result like:
SELECT * FROM Table_Name WHERE TYPE IN ('AB','CD','EF')
Is there any way that can do the trick? Can I use dynamic SQL? If I can, how can I use that in this case?