I am trying to fetch a number of values from a table and store it in a single variable as comma separated values so that I can use that variable as parameter in a different select statement.
Here's the SQL Query:
DECLARE @AccCode VARCHAR(MAX)
SELECT @AccCode = AccCode FROM Account WHERE (*some condition*) --returns more than 1 value
SELECT * FROM AccountSet WHERE AccCode IN (@AccCode)
The problem is that all the values returned from the first select query is not being stored in the @AccCode variable. Instead only the first returned value is being stored.
I am not sure if I'm missing something. Any help would be appreciated.
Thanks in advance..!!