I am having a query like :
declare @aID varchar(max)='1'
declare @pID varchar(max)=' '
SELECT * from Table1 WHERE
(PId = @PID or @pID='') AND (AID = @aID or @aID = '')
This query works fine. But now, I want to use 'IN' clause.
declare @aID varchar(max)='1,2'
SELECT * from Table1 WHERE
(PId = @PID or @pID='') AND (AID IN (@aID) or @aID = '')
But this last query gives me an error.
Error : 'Conversion failed when converting the varchar value '1,2' to data type int'
I do not want to change the design of my Table1
How can I make this possible ?