|
I Have a table where I have to calculate 2 fields for each consumer, for each month. Can I do this query without Cursor? If yes HOW?
(comments are locked)
|
|
I am not sure what you want here. Here you have the monthly Debits-Credits per Customer: The other option would be grouping sets, to give you the Monthly totals and the per customer totals: If this is not what you want, please provide an expected output for your sample data. **** EDIT **** Now that agron has explained what he wanted as the final output, this should do the trick: Edit CET 15:11 - added temp Tally Table, because agron didn't have one - sorry! This query looks OK, but I need results split ed in different column per each month...? example: ConsID, Debt, January, February etc....
Oct 21 '10 at 11:13 PM
Gogolo
The query should provide data like BRILLIANT article from Jeff Moden, but something I don't understand and I cannot build this... I tried your query but I got errors on @SQL2...!?
Oct 22 '10 at 06:04 AM
Gogolo
@Agron - I missed the Tally table that I was using. I now added it to the solution. Look it up on SqlServerCentral (it is from Jeff Moden too).
Oct 22 '10 at 06:13 AM
WilliamD
@WilliamD - is this line right?
Oct 22 '10 at 06:48 AM
ThomasRushton ♦
It is right, query works but I'm not getting proper results, I mean I have record from month 6 (June) and query doesn't create Month 6?
Oct 22 '10 at 07:18 AM
Gogolo
(comments are locked)
|


agron - please supply us with a bit more detail.
Table creation scripts, sample data, expected output and what you have as a query at present.
It is more than likely this can be done without a cursor.
@agron - we like a challenge here, so yes we can do it without a cursor, just give us a little more info though.....:)
I just pasted a script with some data given as example, thank you in advanced!!
Any sample output you want to see?