July 13, 2010 at 6:17 am
I have the following code and I am getting an 'Incorrect Syntax' error. I am using SQL Server 2005 to form a stored procedure and I am a novice at writing procedures. What I am trying to do is set a shift variable. Thanks for the information!
SELECT thistime=Convert(varchar(10),getdate(),108)
shift = CASE thistime
WHEN thistime between '00:00:00' and '06:59:59' --THIRD
'THIRD'
WHEN thistime between '07:00:00' and '14:59:59' --FIRST
'FIRST'
ELSE
'SECOND'
END
July 13, 2010 at 6:24 am
Something like this?
DECLARE @thistime AS VARCHAR(10)
DECLARE @shift AS VARCHAR(10)
SET @thistime = CONVERT(VARCHAR(10), Getdate(), 108)
SELECT @thistime,
shift = CASE
WHEN @thistime BETWEEN '00:00:00' AND '06:59:59' --THIRD
THEN 'THIRD'
WHEN @thistime BETWEEN '07:00:00' AND '14:59:59' --FIRST
THEN 'FIRST'
ELSE 'SECOND'
END
July 13, 2010 at 6:26 am
Yes, thanks! And I love your byline - Not a DBA, but trying to learn!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply