Hi Gene,
Quote:
set @WhatsTheDay='24 March 2009' |
You didn't ask about this, but I hope you are aware that this code
will only run error free if you are using English settings. Change the
language settings to almost any other language, and you get an error
thrown.
The advised way to hardcode dates is to use the YYYYMMDD format:
SET @WhatsTheDay = '20090324';
Quote:
select
datename(dw,datepart(dd,@WhatsTheDay))+', '+ |
It's easy to see what goes wrong here if you try the individual parts:
SELECT datepart(dd,@WhatsTheDay)
returns the integer value 24. As expected. Since this is then used in
a place where a datetime arguument is expected, SQL Server will
implicitly convert to datetime:
SELECT CAST(24 AS datetime);
returns Jan 25th, 1900. Which happens to be a thursday.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis