I have a stored procedure that will be receiving parameters to build the WHERE clause of the SQL statement. I'm allowing users to select more than one item for each column so am having to use the IN clause. My statement looks like the following:
EXEC (N'SELECT col1, col2 FROM Table1 WHERE col1 IN ('+@var1+')')
Both col1 and col2 are varchars. I've managed to get this to work. The problem is when I throw in a date field.
EXEC (N'SELECT col1, col2 FROM Table1 WHERE col1 IN ('+@var1+') AND col3 >= ' + @varDate)
If I leave the varDate variable as a smalldatetime datatype, I receive the error: Incorrect syntax near '¬'. If I change varDate to a varchar, the data is ignored. I receive data prior to the date (less than) in the variable.
I've tried forcing the issue with a CONVERT function to no avail. Anyone have any ideas?
Thank you very much,
WDFog
EXEC (N'SELECT col1, col2 FROM Table1 WHERE col1 IN ('+@var1+')')
Both col1 and col2 are varchars. I've managed to get this to work. The problem is when I throw in a date field.
EXEC (N'SELECT col1, col2 FROM Table1 WHERE col1 IN ('+@var1+') AND col3 >= ' + @varDate)
If I leave the varDate variable as a smalldatetime datatype, I receive the error: Incorrect syntax near '¬'. If I change varDate to a varchar, the data is ignored. I receive data prior to the date (less than) in the variable.
I've tried forcing the issue with a CONVERT function to no avail. Anyone have any ideas?
Thank you very much,
WDFog