Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Date loop
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



Report this thread to moderator Post Follow-up to this message
Old Post
BR
12-14-06 12:12 AM


RE: Date loop
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-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
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Edgardo Valdez, MCTS / MCITP
12-14-06 12:12 AM


Re: Date loop
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
>



Report this thread to moderator Post Follow-up to this message
Old Post
Arnie Rowland
12-14-06 12:12 AM


Re: Date loop
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
>



Report this thread to moderator Post Follow-up to this message
Old Post
Uri Dimant
12-14-06 05:12 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 09:40 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006