I'm trying to concatenate a string inside a sql statement.
I'm using sql server and this is how it looks;
declare
@SchoolID INT
,@Transaction nVarChar(35)
,@Reporting nVarChar(35)
,@SchoolOf nVarChar(35)
,@SchoolYear INT
,@Charter Varchar(25)
,@Value varchar(max)
SET @SchoolID = 105 -- HS - 65, MS - 66, ES - 67
SET @TransactionTypeCode = '' -- '', 'D', 'R'
SET @ReportingLEA = '1'
SET @SchoolOfAttendance = '1' -- HS - 1930056, MS - 6061238, ES - 6010862
SET @SchoolYear =295
SET @Charter = 'ALL'
SET @Value =
CASE @Charter
WHEN 'Los Angeles'
THEN 'Los Angeles'
WHEN'San Diego'
THEN 'San Diego'
WHEN 'Fresno'
THEN 'Fresno'
WHEN 'ALL'
THEN 'Los Angeles' + ',' +'San Diego'+ ','+'Fresno' --trying to concatenate data to show in the clause IN like charter IN ('Los Angeles','San Diego','Fresno')
END
print @Value
What i want is that if the user selects 'All'
then the value of
@Value would be: 'Los Angeles' + ',' +'San Diego'+ ','+'Fresno'
inside the in clause:
AND gsrf.Charter in (@Value)
But is not working.
I believe the in clause doesn't support this kind of concatenation
If run this query and set the variable to 'ALL' then i get this in the print result:
Los Angeles,San Diego,Fresno
But if i run the whole script with this results (without the IN separation) i don't get any data.
Any suggestions?