I have a SQL Server table with fields named Monday, Tuesday,...Sunday
I want to find the day of the week, use that as the field name, and only return records where the field is set to 1.
I have a stored Procedure:
and the error is:Code:CREATE PROCEDURE [dbo].[proc_GetScheduledJobs] AS DECLARE @dayOfWeek VARCHAR(32) SET @dayOfWeek = DATENAME(WEEKDAY, GETDATE()) SELECT @dayOfWeek FROM Table1 WHERE @dayOfWeek=1 /*SELECT Thursday FROM Table1 WHERE Thursday=1*/ GO
Server: Msg 245, Level 16, State 1, Procedure proc_GetScheduledJobs, Line 7
Syntax error converting the varchar value 'Thursday' to a column of data type int.
since today is Thursday.
I tried adding '[' + ']' around the variables but that didn't work.