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 ««12

attempting to recreate complex "multi-layer" Access queries in SSMS Expand / Collapse
Author
Message
Posted Thursday, August 1, 2013 7:46 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, July 24, 2014 9:56 AM
Points: 7,120, Visits: 13,491
R. Brush (8/1/2013)
ChrisM@Work,

I know how to do it. I didn't say it could not be accomplished some other way.

My original post said that an alias cannot be referred to in a subsequent calculation like MS Access allows.

You chose to take issue with that, indicating I was giving misinformation in regards to later versions of SQL Server.

The fact is...an alias cannot be referred to in a subsequent calculation in the same way that MS Access allows. Period.

In the future, please don't say I'm wrong, if I'm not.



ChrisM@Work (7/31/2013)
R. Brush (7/31/2013)
Access lets you define a calculated column in a query and then use the calculated column name in other calculated columns. SQL Server will not allow this. ...


Not in 7,2000, no. But it will in 2005 onwards.


CROSS APPLY lets you define a calculated column in a query and then use the calculated column name in other calculated columns.
You probably mean to say "Access allows you to perform a calculation in the output set (SELECT list) and reference the result of the calculation elsewhere in the output set". I'm ok with that. The original statement, however, is misleading and incorrect.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1479949
Posted Thursday, August 1, 2013 7:51 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 6:39 AM
Points: 101, Visits: 317
ChrisM@Work,

I meant it the exact way vega805 was trying to use it, which is the same way MS Access allows, and the exact way that SQL Server has never allowed.

Have a great day!


Post #1479953
Posted Thursday, August 1, 2013 12:01 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, July 8, 2014 4:56 PM
Points: 10, Visits: 155
R Brush and Chris M, thank you so very much for taking the time for this contribution. This is helpful. I mulled over much of the query yesterday to "see" it myself. Also introduces new clauses to me such as CROSS APPLY. So in ChrisM’s query, post 558, the CROSS APPLY part, is this equivalent to that calculated column concept? Could I also achieve this in a sub query? Purposely asking this for understanding. I sense a limitation - that I would not be able to “refer”, “point” or use the result the sub query calculates, CROSS APPLY will allow this. Ill also reference BOL, although at times the explanations are abstract for me.

Thank you again.


_____________________________________________________________________
As soon as you see something, you already start to intellectualize it. As soon as you intellectualize something, it is no longer what you saw. Suzuki-roshi
Post #1480065
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse