Groups | Blog | Home
all groups > sql server data mining > august 2004 >

sql server data mining : How to add Calendar


Sasha
8/20/2004 9:20:21 AM
I have a schedule table and I need to add to the existing
date column all dates for the year of 2005. The normal
format 1/1/2005. To do it manually will take me forever,
so what type of query can I use to do it.

Thank you,

Adam Machanic
8/21/2004 3:54:40 PM
Sasha,

What do you mean when you say the 'normal format'? A datetime column does
not have a format. If you mean that you're storing the dates as text
strings, why? This is definitely not recommended, especially given the
ambiguous format you posted... For instance, how will a user know what
1/2/2005 represents?

Assuming you're not storing dates as strings, this is probably easiest done
as a loop:


DECLARE @theDate SMALLDATETIME

SET @theDate = '20050101'

WHILE @theDate < '20060101'
BEGIN
INSERT YourTable (YourDateColumn)
VALUES (@theDate)

SET @theDate = DATEADD(dd, 1, @theDate)
END

If you are storing dates as strings, you can use CAST or CONVERT to get the
date into whatever string format you want... But please think about
converting to a SMALLDATETIME datatype.


[quoted text, click to view]

anonymous NO[at]SPAM discussions.microsoft.com
8/23/2004 8:42:16 AM
Thanks a lot!
[quoted text, click to view]
AddThis Social Bookmark Button