Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesPlease 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
Post Follow-up to this messageyou 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-0 1 > 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 > > >
Post Follow-up to this messageYou 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 >
Post Follow-up to this messageBR 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 >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread