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:
00901359
Views:
16
Mike,

Thank you for the reply. The derived tables example is exactly what I was looking for. I just had to make one small syntax chage for it to execute properly:

SELECT qtrs.qtr1, qtrs.qtr2, qtrs.qtr1+qtrs.qtr2 AS firstHalf FROM (
SELECT SUM(jan+feb+mar) AS qtr1, SUM(apr+may+jun) AS qtr2 FROM myTable ) as qtrs

It looks like I have to use an alias name for the derived tabel. Thank you again for great suggestion!

Kind Regards,

Mat


>SQL Server won't give you the behavior that you're looking for. I can think of two ways to get the behavior that your looking for.
>
>1) Use views
>
>CREATE VIEW qtrs AS
>SELECT SUM(jan+feb+mar) AS qtr1, SUM(apr+may+jun) AS qtr2 FROM myTable
>
>SELECT qtr1, qtr2, qtr1+qtr2 AS firstHalf FROM qtrs
>
>2) Use derived tables
>
>SELECT qtr1, qtr2, qtr1+qtr2 AS firstHalf FROM (
> SELECT SUM(jan+feb+mar) AS qtr1, SUM(apr+may+jun) AS qtr2 FROM myTable )
>
>-Mike
>
Matthew Kennedy
Decision Support Technology Inc.

"I try to take one day at a time, but sometimes several days attack me all at once." ~ Ashleigh Brilliant

New Jersey Dot Net User Group
Previous
Reply
Map
View

Click here to load this message in the networking platform