TJT (5/15/2013)
I am trying to create a variable like the following in a WHERE clauseDECLARE @test-2 AS VARCHAR(90)
SET @test-2 = '2003 OR Cars.year = 2004 OR Cars.year = 2004'
SELECT Cars.year
FROM CARS
WHERE Cars.year = @test-2
Is this possible to set a variable like this? I need to escape the "OR Cars.year =" part it seems
No, it's invalid T-SQL construction.
You should use the following:
SELECT Cars.year
FROM CARS
WHERE Cars.year IN (2003,2004,2005)
or you can build the whole statement as dynamic SQL and execute it, however I don't think that is really applicable for your case.