Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Use calculated value in the same select
Message
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
00901314
Message ID:
00901325
Views:
18
Mat,

I'd say it depends on what database you're using. SQL Server does not support this type of syntax, but I don't know about other databases (like maybe Oracle). BTW, for the particular example you gave, you could always do something like this instead:
select sum(jan+feb+mar) as qtr1, 
       sum(apr+may+jun) as qtr2, 
       sum(jan+feb+mar+apr+may+jun) as first6months 
  from myTable
~~Bonnie

>I am trying to calculate some monthly totals and then use those totals in another column. Something like this:
>
>select sum(jan+feb+mar) as qtr1, sum(apr+may+jun) as qtr2, sum(qtr1+qtr2) as first6months from myTable
>
>Do I need to do this in a subquery or is there some way to use an alias to refer to the calculated qtr amounts?
>
>Kind Regards,
>
>Mat
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform