I'm trying to use a multi valued string in a Store Procedure, but the IN operator is only accepting the values in Hard Coded mode.
Like, if I write the values directly in the Code it works, but if the value is retrieved from the SELECT command, it return nothing...
Anyone can help on this?
For testing:
DECLARE @AUX nvarchar(255);
SET @AUX = (SELECT GROUP FROM FRUITS WHERE FRUIT = 'APPLES');
PRINT @AUX;
SELECT *
FROM FRUITS
WHERE FRUIT IN (@AUX);
This returns nothing. But the value inside @AUX
is retrieved, and contains something like 'Red','Green','Starkling'
.
If I use that Select
command only it works.
And if I hard core inside the IN the Values it works also.
SELECT *
FROM FRUITS
WHERE FRUIT IN ('Red', 'Green', 'Starkling');
This works.
I tried to output the value inside the variable @AUX and is correct... So why the IN doesn't read the values?
TIA