SELECT Col1, Col2, Col3, Col4
FROM Table1
WHERE User1 = @Owner
AND group1 = @Group
AND date1 BETWEEN @startDate AND @endDate
AND Mail LIKE @email
AND def IN (CASE @InvoiceMethod //Problem is Here
WHEN ''
THEN def
ELSE (@InvoiceMethod)
END)
A piece of code from the stored procedure. If am executing this, it's not returning any rows, even though it has some to return. Problem is with the IN
clause, if I didn't pass anything to IN
clause i.e @InvoiceMethod
is null, then I'm getting rows.
If I pass anything to @InvoiceMethod
, I'm not getting any rows.
The value in @InvoiceMethod
is = 'A','B'
I tried many combinations like 'A','B'
or "A","B"
without any results.
How to pass values to IN
clause please? In which format?
Please help me out of this.
Modified the stored procedure to the following,
Declare @tmpt table (value nvarchar(5) not null)
SET @InvoiceCount=(select COUNT(*) from dbo.fnSplit(@InvoiceMethod, ','))
SET @tempVar=1;
WHILE @tempVar<=(@InvoiceCount)
BEGIN
INSERT INTO @tmpt (value)
VALUES (@InvoiceMethod);//Here i need to insert array of values to temp table.like invoicemethod[0],invoicemethod[1]&invoicemethod[2] depends on @InvoiceCount
SET @tempVar=@tempVar+1;
END
--DECLARE @tmpt TABLE (value NVARCHAR(5) NOT NULL)
--INSERT INTO @tmpt (value) VALUES (@InvoiceMethod);
SELECT Col1,Col2,Col3,Col4
FROM Table1
WHERE User1 = @Owner
AND group1 = @Group
AND date1 between @startDate AND @endDate
AND Mail LIKE @email
AND def IN (SELECT value FROM @tmpt)
But not getting the results as expected :(