I am writing a stored proc and I can't get it right in one part, wehre I have to "convert" a date stored as an integer (with the format yyyymmdd, i.e. 20180126 for example for today, to a smalldatetime local variable.
Here the code for that part:
DECLARE @LastWorkingDay int
DECLARE @dLWD smalldatetime
DECLARE @sLWD char(8)
-- Get the last working day from the DB table
SELECT @LastWorkingDay = LastWorkingDay FROM [dbo].[V_Dates];
-- Convert it to a string
SET @sLWD = CAST(@LastWorkingDay as char(8))
-- Chop the bits up to convert it to YYYY-MM-DD format and cast it to smalldattime
SET @dLWD = CAST(Left(@sLWD, 4) + '-' + SUBSTRING(@sLWD, 5, 2) + '-' + Right(@sLWD, 2) as smalldatetime)
One of the SET line gives an "Incorrect syntax near the keyword 'SET'" error. I say one because I don't quite know how SQL Server is counting the lines in a stored proc.
Can you tell me what is wrong in my code ?
Also, can you tell me how I can see the progress of the steps in a stored proc, is there some kind of an equivalent to Console.WriteLine in VB or C#, seemingly I could also get the status back but I also don't know how to do that.
Thanks a lot