Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Use expression value as column name in same query again Expand / Collapse
Author
Message
Posted Wednesday, November 18, 2009 3:27 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 4, 2010 12:19 AM
Points: 94, Visits: 60
I want to Use expression value as column name in same query again

For eg:

select productname, (uprice+sprice) As pprice, CASE WHEN IsNull(pprice) Then '0' Else pprice End As pprice2 from products where active=1, productname is not null

Here pprice is the value I am calculating and want to be able to refer it in the same query without having to write the calculation again. This is just a simple example but the actual calculated column is complicated and very long and it makes it very difficult to debug if I have to use the same code again and again. Is there a cleaner way to do this in same query?




Post #821250
Posted Wednesday, November 18, 2009 3:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:24 PM
Points: 7,121, Visits: 15,024
Please don't cross-post.

conversation is already ongoing over here:

http://www.sqlservercentral.com/Forums/FindPost821231.aspx


----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #821258
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse