SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The Cascading (CROSS) APPLY


The Cascading (CROSS) APPLY

Author
Message
ChrisM@home
ChrisM@home
SSCrazy Eights
SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)

Group: General Forum Members
Points: 9499 Visits: 10705
Comments posted to this topic are about the item The Cascading (CROSS) APPLY


Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




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
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)

Group: General Forum Members
Points: 377064 Visits: 42913
Awesome job, Chris. Well done!

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Tim Walker.
Tim Walker.
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2183 Visits: 1007
Interesting, entertaining and educational with worked examples and performance statistics make this a great read.

The fact that it is also genuinely very useful and will help me to accurately solve a problem I have right now makes it invaluable.

Great job Chris. Thanks for sharing.

.
balde
balde
SSC Eights!
SSC Eights! (988 reputation)SSC Eights! (988 reputation)SSC Eights! (988 reputation)SSC Eights! (988 reputation)SSC Eights! (988 reputation)SSC Eights! (988 reputation)SSC Eights! (988 reputation)SSC Eights! (988 reputation)

Group: General Forum Members
Points: 988 Visits: 621
Ever since discovering a use for APPLY for the first time approximately 2 years ago, I've found I use it almost everywhere these days.

To the extent where I start looking for candidates for re-writing using APPLY! --> thankfully I'm about to move onto pastures new so the 7 years worth of stored procedures and queries I have here will no longer be candidates for such an exercise!

APPLY truly is a remarkable technique and this article adds another strong argument to the reasons why you should have this in your arsenal - if you don't yet feel confident working with APPLY work through the examples here and you'll see how powerful it is.

thanks for another great article and keep up the good work



ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)

Group: General Forum Members
Points: 72623 Visits: 20304
Jeff Moden (4/16/2013)
Awesome job, Chris. Well done!


Thanks Jeff! And thank you for the encouragement to put pen to paper. DC's been nagging me for ages. Once you stepped in there was no getting out of it :-D

“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
ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)

Group: General Forum Members
Points: 72623 Visits: 20304
Tim Walker. (4/16/2013)
Interesting, entertaining and educational with worked examples and performance statistics make this a great read.

The fact that it is also genuinely very useful and will help me to accurately solve a problem I have right now makes it invaluable.

Great job Chris. Thanks for sharing.


Thank you very much, Tim. Almost every day, something comes up on ssc which requires a cCA or some other manipulation of APPLY. I don't know what we did without it.

“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
ChrisM@home
ChrisM@home
SSCrazy Eights
SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)

Group: General Forum Members
Points: 9499 Visits: 10705
balde (4/16/2013)
Ever since discovering a use for APPLY for the first time approximately 2 years ago, I've found I use it almost everywhere these days.

To the extent where I start looking for candidates for re-writing using APPLY! --> thankfully I'm about to move onto pastures new so the 7 years worth of stored procedures and queries I have here will no longer be candidates for such an exercise!

APPLY truly is a remarkable technique and this article adds another strong argument to the reasons why you should have this in your arsenal - if you don't yet feel confident working with APPLY work through the examples here and you'll see how powerful it is.

thanks for another great article and keep up the good work


Thank you balde, and best wishes with your new venture.


Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




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
Gary Nease
Gary Nease
SSC-Enthusiastic
SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)

Group: General Forum Members
Points: 165 Visits: 500
In the initial CREATE TABLE example, [RowNum] should be [EmployeeId].

Thanks for the great article.


Regards,

Gary
ChrisM@home
ChrisM@home
SSCrazy Eights
SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)

Group: General Forum Members
Points: 9499 Visits: 10705
Gary Nease (4/16/2013)
In the initial CREATE TABLE example, [RowNum] should be [EmployeeId].

Thanks for the great article.


Thank you very much Gary - duly updated.


Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




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
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)SSC Guru (377K reputation)

Group: General Forum Members
Points: 377064 Visits: 42913
ChrisM@Work (4/16/2013)
Tim Walker. (4/16/2013)
Interesting, entertaining and educational with worked examples and performance statistics make this a great read.

The fact that it is also genuinely very useful and will help me to accurately solve a problem I have right now makes it invaluable.

Great job Chris. Thanks for sharing.


Thank you very much, Tim. Almost every day, something comes up on ssc which requires a cCA or some other manipulation of APPLY. I don't know what we did without it.


For single row things, we use to use "Correlated Sub-Queries" in the SELECT list. Of course, those didn't have the flexibility of returning multiple rows like Cross Apply does.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
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