June 24, 2015 at 12:00 am
Comments posted to this topic are about the item Stairway to Advanced T-SQL Level 6: Creating Rows Of Data Using The UNPIVOT Operator
Gregory A. Larsen, MVP
June 24, 2015 at 7:19 am
Greg Larsen (4/27/2015)
Comments posted to this topic are about the item <A HREF="/articles/Stairway+Series/125504/">Stairway to Advanced T-SQL Level 6: Creating Rows Of Data Using The UNPIVOT Operator</A>
Consider using CROSS APPLY instead of UNPIVOT. More flexible (can unpivot multiple columns at once) and can generate better plans.
Unpivot a table using cross apply[/url]
Gerald Britton, Pluralsight courses
June 25, 2015 at 7:21 am
I'm still a little confused, but good start for me anyway.
June 25, 2015 at 7:45 am
g.britton (6/24/2015)
Greg Larsen (4/27/2015)
Comments posted to this topic are about the item <A HREF="/articles/Stairway+Series/125504/">Stairway to Advanced T-SQL Level 6: Creating Rows Of Data Using The UNPIVOT Operator</A>Consider using CROSS APPLY instead of UNPIVOT. More flexible (can unpivot multiple columns at once) and can generate better plans.
CROSS APPLY VALUES is a more specific term for the use of CROSS APPLY in a manual unpivot. Dwain's written a great article here[/url].
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
June 30, 2015 at 6:31 am
ChrisM@Work (6/25/2015)
g.britton (6/24/2015)
Greg Larsen (4/27/2015)
Comments posted to this topic are about the item <A HREF="/articles/Stairway+Series/125504/">Stairway to Advanced T-SQL Level 6: Creating Rows Of Data Using The UNPIVOT Operator</A>Consider using CROSS APPLY instead of UNPIVOT. More flexible (can unpivot multiple columns at once) and can generate better plans.
CROSS APPLY VALUES is a more specific term for the use of CROSS APPLY in a manual unpivot. Dwain's written a great article here[/url].
Well it makes no difference if you use VALUES or SELECT with a UNION ALL. That is:
with cte as
(
select 1 as one, 2 as two, 3 as three, 4 as four
)
select a, b
from cte
cross apply
(
select one, two
union all
select three, four
--values (one,two),
-- (three,four)
) upvt(a, b)
works just the same if you comment the SELECTs in the cross apply and uncomment the VALUES. Granted, the second is a little less typing but the functionality is the same I believe (as is the actual execution plan, I think). I would even argue that the SELECT...UNION ALL is a little more flexible since you can add where clauses if needed
Gerald Britton, Pluralsight courses
January 5, 2022 at 11:27 am
This was removed by the editor as SPAM
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply