|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
1. print current count 2. decrement date 3. subtract previous count from new countset @today = '2006-01-12' select count( var1 ) from customer where var_DT > @today 1. Print or capture the counts for var 1 given 'where var_DT > @today' 2. Decrement @today (@today - 1) iteration 1. '2006-01-12' iteration 2 2006-01-13' iteration 3 '2006-01-11' .... 3. Repeat, printing the result of subtracting the count value from the previous iteration from the new count in the current iteration. the results will look in my case something like the following where I want to print the result as 30, 35, 20,15, etc. Iteration 1 - 30 Iteration 2 - 65 - 30 = 35 Iteration 3 - 85 - 65 = 20 Iteration 4 - 100 - 85 = 15 Iteration 5 - new count - count from previous step = value to print or capture Thank you! -greg On Thu, 12 Jan 2006 09:09:06 -0800, hazz wrote:
Show quote >declare @today datetime Hi Greg,>set @today = '2006-01-12' >select count( var1 ) from customer where var_DT > @today > >1. Print or capture the counts for var 1 given 'where var_DT > @today' >2. Decrement @today (@today - 1) > iteration 1. '2006-01-12' > iteration 2 2006-01-13' > iteration 3 '2006-01-11' > .... >3. Repeat, printing the result of subtracting the count value from the >previous iteration from the new count in the current iteration. > >the results will look in my case something like the following where I want >to print the result as 30, 35, 20,15, etc. > > Iteration 1 - 30 > Iteration 2 - 65 - 30 = 35 > Iteration 3 - 85 - 65 = 20 > Iteration 4 - 100 - 85 = 15 > Iteration 5 - new count - count from previous step = value to >print or capture I'm not sure if I understand what you are asking. Are you looking for a single set-based query to produce the same results as the procedural description above would give? Anyway, the best way to ask for help and avoid misunderstandings is to provide: - Table structure, as CREATE TABLE statements, including all constraints and properties. Irrelevant columns may be omitted, - Some rows of sample data (as INSERT statements) to illustrate the problem, - The expected results, - And a short explanation of the business problem that you're trying to solve. Check out www.aspfaq.com/5006 for some tips on how to assemble the CREATE TABLE and INSERT statements. -- Hugo Kornelis, SQL Server MVP |
|||||||||||||||||||||||