Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compound Select
Message
 
 
To
28/08/2008 12:36:46
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
01342599
Message ID:
01342643
Views:
9
>>select (sum(iif(Month=1,Amount,000000000000)) as Jan, ...., Year, Category group by Year, Category - use this as a derived table.
>>
>>Actually, looks like this select alone will give you what you want.
>
>There should be no need to sum. We are not combining records, only positioning them. What I'm getting is:
>Category, Sep, Oct, Nov, Fisyear
>Cat1, ##.##, ##.##, ##.##,2007
>Cat2, ##.##, ##.##, ##.##,2007
>Cat3, ##.##, ##.##, ##.##,2007
>
>What I want is:
>Category, Sep, Oct, Nov, Fisyear
>Cat1, ##.##, ##.##, ##.##,2007
>Cat2, ##.##, ##.##, ##.##,2007
>Cat3, ##.##, ##.##, ##.##,2007
>Cat1, ##.##, ##.##, ##.##,2008
>Cat2, ##.##, ##.##, ##.##,2008
>Cat3, ##.##, ##.##, ##.##,2008
>
>The reason I'm only getting the first year is because the first cursor (crsA) which contains the year, is not being iterated. I had thought that I could use the second select as the derived table and wrap it into the first as in
>select dist fisyear,  ;
>(select dist category, ;
>		nvl((select amount ;
>		from rta_revenues ;
>		where fisyear = crsA.fisyear and ;
>		category = crsB.category and ;
>		month(receiveddate) = 9),0) as sep , ;		
>		nvl((select amount ;
>		from rta_revenues ;
>		where fisyear = crsA.fisyear and ;
>		category = crsB.category and ;
>		month(receiveddate) = 10),0) as oct , ;
>		nvl((select amount ;
>		from rta_revenues ;
>		where fisyear = crsA.fisyear and ;
>		category = crsB.category and ;
>		month(receiveddate) = 11),0) as nov , ;
>		crsA.fisyear as fisyear ;
>		from rta_revenues crsB) ;
> from rta_revenues crsA order by fisyear
>
>but this throws an error that says the subquery is invalid.

Re-read my message one more time (I made a small change). If you only have one record per category in a month, then just remove SUM from my select statement and group by. It would give you the result you want, very simple select.
select Category, CAST(iif(Month(receiveddate)=1,Amount,0000000000.00) as N(5,2)) as Jan, ...., FisYear
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform