Results 1 to 1 of 1

Thread: reuse select query result

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    reuse select query result

    Hi,

    I have a SQL select query, it works fine as it is now.
    Code:
    select namee as 'FULL NAME', 
    sum(inn)  as 'Money', sum(case when color='red' or color='MEDIUM red' or color = 'LIGHT red' then isnull(out,0) else 0       End) as 'FIRST RESULT',
    sum(case when color='red' or color='MEDIUM LIGHT red' then isnull(inn,0) - isnull(out,0) else 0       End) as 'SECOND RESULT'
    from yyyyyyyy where  ID = 100 group by namee
    But I would like to be able to get the result of each case ex: final result of "FIRST RESULT" and "SECOND RESULT" and to be able to reuse it in my next line of code like
    Code:
    sum(case when color='red' or color='MEDIUM LIGHT red' then isnull(inn,0) - isnull('FIRST RESULT',0) else 0       End) as 'THIRD RESULT'
    I'm not sure how i can accomplish that, any tip will be appreciated.

    Thanks
    Last edited by met0555; Oct 9th, 2012 at 11:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width