I would like to create a report in SQL Analyzer. Is there a For Next
construct or equivalent?
declare @.now datetime
set @.now = '2005-09-19 17:57:00.00'
for i = 1 to 60 -- pseudocode
select @.now
select count(Create_DT) from customer where EmailSent_DT > @.now and
EmailSent_IN = 1
select count(Create_DT) from customer where EmailSent_DT > @.now and
EmailSent_IN = 2
next
********** output results *****************
Col1 Col2
Col3
date Count(query result based on date)
Count(query result based on date)
date + 1 day Count(query result based on date + 1)
Count(query result based on date + 1 )
date + 2 day Count(query result based on date + 2)
Count(query result based on date + 2)
date + 3 day Count(query result based on date + 3)
Count(query result based on date + 3)
******************************
thank you - gregThere is a WHILE loop construct in SQL. However, for general application
related tasks, it is seldom needed. If you post your table structures,
sample schema & expected results ( www.aspfaq.com/5006 ) someone here can
perhaps show you how to generate the required resultset without iteration.
One general trick employed in SQL for such requirements is using a table of
sequentially incrementing numbers. You can find several solutions related to
this, if you search the archives of this newsgroup.
Anith|||Try using WHILE with a counter and then increment the counter in the code.
HTH
Jerry
"hazz" <hazz@.sonic_net> wrote in message
news:eMk64gN0FHA.2064@.TK2MSFTNGP09.phx.gbl...
>I would like to create a report in SQL Analyzer. Is there a For Next
>construct or equivalent?
> declare @.now datetime
> set @.now = '2005-09-19 17:57:00.00'
> for i = 1 to 60 -- pseudocode
> select @.now
> select count(Create_DT) from customer where EmailSent_DT > @.now and
> EmailSent_IN = 1
> select count(Create_DT) from customer where EmailSent_DT > @.now and
> EmailSent_IN = 2
> next
> ********** output results *****************
> Col1 Col2 Col3
> date Count(query result based on date) Count(query
> result based on date)
> date + 1 day Count(query result based on date + 1) Count(query
> result based on date + 1 )
> date + 2 day Count(query result based on date + 2) Count(query
> result based on date + 2)
> date + 3 day Count(query result based on date + 3) Count(query
> result based on date + 3)
> ******************************
> thank you - greg
>|||Beautiful. Thank you.
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:OgT8xoN0FHA.3904@.TK2MSFTNGP15.phx.gbl...
> Try using WHILE with a counter and then increment the counter in the code.
> HTH
> Jerry
> "hazz" <hazz@.sonic_net> wrote in message
> news:eMk64gN0FHA.2064@.TK2MSFTNGP09.phx.gbl...
>
Monday, March 19, 2012
create report incrementing date on left and results based on that date in subsequent
Labels:
2005-09-19,
analyzer,
based,
create,
database,
date,
datetimeset,
equivalentdeclare,
incrementing,
microsoft,
mysql,
nextconstruct,
oracle,
report,
server,
sql,
subsequent
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment