Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


attempting to recreate complex "multi-layer" Access queries in SSMS


attempting to recreate complex "multi-layer" Access queries in SSMS

Author
Message
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9028 Visits: 19041
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
R. Brush
R. Brush
SSC-Enthusiastic
SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)

Group: General Forum Members
Points: 117 Visits: 347
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!
vega805
vega805
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 233
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search