|
Home > Archive > MS SQL Server > June 2005 > Calendar Table
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I am trying to get all dates starting from June 20 , 2004 to yesterday but
the table includes today's that (which i dont want).
DECLARE @Tmp TABLE (DOM smalldatetime)
DECLARE @day smalldatetime
DECLARE @DOM smalldatetime
SET @day = 'June 20, 2004'
WHILE @day < GetDate()
BEGIN
INSERT INTO @Tmp
SELECT @day as DOM
SET @Day = @Day + 1
END
| |
| Keith Kratochvil 2005-06-29, 1:23 pm |
| @day is not < GETDATE() until it hits the next day (because of the time
component). You need to remove the time component from GETDATE() somehow.
I have done so in the example below:
DECLARE @Tmp TABLE (DOM smalldatetime)
DECLARE @day smalldatetime
DECLARE @DOM smalldatetime
SET @day = 'June 20, 2004'
WHILE @day < CONVERT(datetime,CON
VERT(char(8),GetDate
(),112))
BEGIN
INSERT INTO @Tmp
SELECT @day as DOM
SET @Day = @Day + 1
END
--
Keith
"Asim" <Asim@discussions.microsoft.com> wrote in message
news:090F9AA5-BF5D-44C4-9405- 96D6D7276493@microso
ft.com...
>I am trying to get all dates starting from June 20 , 2004 to yesterday but
> the table includes today's that (which i dont want).
>
> DECLARE @Tmp TABLE (DOM smalldatetime)
> DECLARE @day smalldatetime
> DECLARE @DOM smalldatetime
>
> SET @day = 'June 20, 2004'
>
> WHILE @day < GetDate()
> BEGIN
> INSERT INTO @Tmp
> SELECT @day as DOM
> SET @Day = @Day + 1
> END
| |
|
| Thankyou very much..
"Keith Kratochvil" wrote:
> @day is not < GETDATE() until it hits the next day (because of the time
> component). You need to remove the time component from GETDATE() somehow.
> I have done so in the example below:
>
> DECLARE @Tmp TABLE (DOM smalldatetime)
> DECLARE @day smalldatetime
> DECLARE @DOM smalldatetime
>
> SET @day = 'June 20, 2004'
>
> WHILE @day < CONVERT(datetime,CON
VERT(char(8),GetDate
(),112))
> BEGIN
> INSERT INTO @Tmp
> SELECT @day as DOM
> SET @Day = @Day + 1
> END
>
>
>
> --
> Keith
>
>
> "Asim" <Asim@discussions.microsoft.com> wrote in message
> news:090F9AA5-BF5D-44C4-9405- 96D6D7276493@microso
ft.com...
>
>
>
|
|
|
|
|