I’m want to use a set of variable to define some often changing values in a subsequent SQL statement. The problem is that I want to define the entire contents of an In statement in a Where clause with a single variable. I’ve set up the “correct” value for the variable using Char(39) which represents “'” (see code below). When I put the variable into the statement however I do not get a result. I've tested it, and I can get datetime variables right, but not my nvarchars for my In statements.What am I doing wrong?TSQL I’m using to declare and set the variables is as follows:DECLARE @Start_Date datetime , @End_Date datetime , @Region nvarchar(75) , @EQ_Market_Cluster nvarchar(100)SET @Start_Date = cast(convert(varchar(8),getdate()-1,1) as datetime)SET @End_Date = cast(convert(varchar(8),getdate(),1) as datetime)SET @Region = CHAR(39) + 'NSD' + CHAR(39) + ',' + CHAR(39) + 'NORTHEAST' + CHAR(39) + ',' + CHAR(39) + 'CENTRAL' + CHAR(39) + ',' + CHAR(39) + 'SOUTHEAST' + CHAR(39) + ',' + CHAR(39) + 'WEST' + CHAR(39)SET @EQ_Market_Cluster = CHAR(39) + 'NEW ENGLAND' + CHAR(39) + ',' + CHAR(39) + 'GEORGIA' + CHAR(39)PRINT '@Start_Date = ' + cast(convert(datetime,@Start_Date) as varchar(12))PRINT '@End_Date = ' + cast(convert(datetime,@End_Date) as varchar(12))PRINT '@Region = ' + @RegionPRINT '@EQ_Market_Cluster = ' + @EQ_Market_Cluster
This is the respose from the print commands when I run the SQL in Aqua: Warnings: ---> W (1): @Start_Date = Dec 25 2007 W (2): @End_Date = Dec 26 2007 W (3): @Region = 'NSD','NORTHEAST','CENTRAL','SOUTHEAST','WEST' W (4): @EQ_Market_Cluster = 'NEW ENGLAND','GEORGIA'