|
Home > Archive > MS SQL Server > December 2006 > Date loop
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]
|
|
|
| Please Help!
I am looking for a way to automatically loop thru dates starting 2006-01-01
thru 2006-12-01. The field I am trying to query is called endts.
I need to know where endts between '2006-01-01 12:00:00AM' and '2006-01-01
12:00:00PM'
I need to loop thru this everyday from 2006-01-01 thru 2006-12-01.
Could someone please post sample code on how this can be done. If it is
possible.
Thanks in Advance.
BR
| |
| Edgardo Valdez, MCTS / MCITP 2006-12-13, 7:12 pm |
| you can try this one:
declare @enddate datetime
declare @loopdate datetime
set @loopdate = '2006-01-01 12:00:00AM'
set @enddate = '2006-12-01 12:00:00PM'
while @loopdate <= @enddate
begin
select @loopdate -- Put your code here
set @loopdate = @loopdate+1
end
"BR" wrote:
> Please Help!
>
> I am looking for a way to automatically loop thru dates starting 2006-01-01
> thru 2006-12-01. The field I am trying to query is called endts.
>
> I need to know where endts between '2006-01-01 12:00:00AM' and '2006-01-01
> 12:00:00PM'
>
> I need to loop thru this everyday from 2006-01-01 thru 2006-12-01.
> Could someone please post sample code on how this can be done. If it is
> possible.
>
> Thanks in Advance.
> BR
>
>
>
| |
| Arnie Rowland 2006-12-13, 7:12 pm |
| You may find that this, and similar date related tasks, are best done using
a Calendar Table.
See:
Datetime -Calendar Table
http://www.aspfaq.com/show.asp?id=2519
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"BR" <so> wrote in message news:%23Cq1lVuHHHA.4712@TK2MSFTNGP04.phx.gbl...
> Please Help!
>
> I am looking for a way to automatically loop thru dates starting
> 2006-01-01 thru 2006-12-01. The field I am trying to query is called
> endts.
>
> I need to know where endts between '2006-01-01 12:00:00AM' and '2006-01-01
> 12:00:00PM'
>
> I need to loop thru this everyday from 2006-01-01 thru 2006-12-01.
> Could someone please post sample code on how this can be done. If it is
> possible.
>
> Thanks in Advance.
> BR
>
| |
| Uri Dimant 2006-12-14, 12:12 am |
| BR
Can you post DDL+ sample data + an expected result?
SELECT <columns> FROM Table WHERE dtcolumn >= '20060101 12:00:00' AND
dtcolumn < DATEADD(d,1,'2006010
1' )
"BR" <so> wrote in message news:%23Cq1lVuHHHA.4712@TK2MSFTNGP04.phx.gbl...
> Please Help!
>
> I am looking for a way to automatically loop thru dates starting
> 2006-01-01 thru 2006-12-01. The field I am trying to query is called
> endts.
>
> I need to know where endts between '2006-01-01 12:00:00AM' and '2006-01-01
> 12:00:00PM'
>
> I need to loop thru this everyday from 2006-01-01 thru 2006-12-01.
> Could someone please post sample code on how this can be done. If it is
> possible.
>
> Thanks in Advance.
> BR
>
|
|
|
|
|