Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss Content Posted by Jeff Moden
»
Cross Tabs and Pivots, Part 2 - Dynamic Cross...
126 posts, Page 2 of 13
««
1
2
3
4
5
»
»»
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Rate Topic
Display Mode
Topic Options
Author
Message
ChrisM@Work
ChrisM@Work
Posted Wednesday, December 03, 2008 8:41 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 6:31 AM
Points: 5,602,
Visits: 10,954
Top work, Jeff. You have a rare talent for mixing informal narrative with a technically challenging subject - and with ruthless precision
Cheers
ChrisM
“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 #612909
mtassin
mtassin
Posted Wednesday, December 03, 2008 8:53 AM
Hall of Fame
Group: General Forum Members
Last Login: Today @ 6:08 AM
Points: 3,226,
Visits: 64,113
That was just an amazing read... learned some neat tricks that I didn't even think were possible (but in retrospect should have known)... very informative...
--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Post #612921
mlandry
mlandry
Posted Wednesday, December 03, 2008 9:20 AM
Forum Newbie
Group: General Forum Members
Last Login: Friday, April 12, 2013 12:57 PM
Points: 1,
Visits: 10
Jeff,
Whoa, using SQL to do cross-tabs really is "old school" (circa mid-90's or before.) It just wasn't designed for this.
Do yourself a BIG favor and try Analysis Services. The MDX language is everything the SQL "select-groupby" ever wanted to be when it grew up. And it's far more expressive in terms of business reporting than SQL will ever be.
Mark Landry
Tampa, FL
Post #612951
Jeff Moden
Jeff Moden
Posted Wednesday, December 03, 2008 9:41 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 9:57 PM
Points: 32,893,
Visits: 26,771
mlandry (12/3/2008)
Jeff,
Whoa, using SQL to do cross-tabs really is "old school" (circa mid-90's or before.) It just wasn't designed for this.
Do yourself a BIG favor and try Analysis Services. The MDX language is everything the SQL "select-groupby" ever wanted to be when it grew up. And it's far more expressive in terms of business reporting than SQL will ever be.
Mark Landry
Tampa, FL
Thanks, Mark... yep... I absolutely agree with everything you said. But, it is a bit more difficult to setup Analysis Services and learn the MDX language than it is to learn how to do a simple cross-tab. Lot's of folks/shops just won't go through it. Not saying that's right or wrong, but simply a fact based on the number of requests for help on cross-tabs on these forums in the last 12 months or so. I figured that if they're going to write a cross tab, they might as well learn how to do it without a cursor or While loop. :)
It just wasn't designed for this.
Heh... T-SQL wasn't designed for most of what I do with it... :P
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
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."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #612980
mtassin
mtassin
Posted Wednesday, December 03, 2008 10:04 AM
Hall of Fame
Group: General Forum Members
Last Login: Today @ 6:08 AM
Points: 3,226,
Visits: 64,113
My favorite way to do cross-tabs is to cheat..
Put the data into a cross tab friend format (measures and values to break it out by)
and feed it into crystal reports.
--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Post #612999
DPhillips-731960
DPhillips-731960
Posted Wednesday, December 03, 2008 10:08 AM
Ten Centuries
Group: General Forum Members
Last Login: Friday, August 10, 2012 6:08 PM
Points: 1,156,
Visits: 801
Thank you for your efforts here Jeff. An article of this level takes hours to prepare, and the effort shows. Although I am an Analysis Server and Report Server convert, I still think this kind of TSQL workup is useful for instruction on many levels, and is the type of project that demonstrates to the less informed that server-side TSQL is far more than just CRUD (A.K.A. READ or SUID). I love dynamic code projects. I dislike static hard-coded unyeiding inflexible and dead-when-deployed code.
You are very spot-on when you say TSQL allows you to do many things not originally designed (but powerful and useful just the same).
Post #613004
WayneS
WayneS
Posted Wednesday, December 03, 2008 10:13 AM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 10:50 AM
Points: 6,367,
Visits: 8,227
Jeff Moden (12/3/2008)
Heh... T-SQL wasn't designed for most of what I do with it... :P
Isn't that the truth.
Fantastic article! Thanks!
Wayne
Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then
DON'T USE IT
on a production system! After all,
you
will be the one supporting it!
Links:
For better assistance in answering your questions
,
How to ask a question
,
Performance Problems
,
Common date/time routines
,
CROSS-TABS and PIVOT tables Part 1
&
Part 2
,
Using APPLY Part 1
&
Part 2
,
Splitting Delimited Strings
Post #613007
jcraddock
jcraddock
Posted Wednesday, December 03, 2008 10:49 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, April 05, 2013 1:30 PM
Points: 104,
Visits: 97
I've had better luck writing code that writes my SQL. I wrote a set of code that you point at any table, it accepts any column within the table as the top or left portion of the crosstab and any numeric column as the data portion. Another option is to calculate as percent of the whole or sum or count.
Doing it that way, you have one set of reusable code for all crosstabs...works pretty well. I usually just create a simple view, point the object at the view and Voila have instant reconfigurable, groupable by anything crosstab. I even added an option to subgroup on the left side.
Same concept, more code up front, but infinitely reusable.
Post #613023
RBarryYoung
RBarryYoung
Posted Wednesday, December 03, 2008 11:00 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
Great article, Jeff. Like
The Return of the King
, it was well worth the wait!
:)
-- RBarryYoung
,
(302)375-0451
blog:
MovingSQL.com
, Twitter:
@RBarryYoung
Proactive
Performance Solutions, Inc.
"Performance is our middle name."
Post #613035
RBarryYoung
RBarryYoung
Posted Wednesday, December 03, 2008 11:04 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
mlandry (12/3/2008)
Whoa, using SQL to do cross-tabs really is "old school" (circa mid-90's or before.) It just wasn't designed for this.
Do yourself a BIG favor and try Analysis Services. The MDX language is everything the SQL "select-groupby" ever wanted to be when it grew up. And it's far more expressive in terms of business reporting than SQL will ever be.
I am sure that a similar article on how to use Analysis Services/MDX to do this for those of us who are T-SQL wonks only, would be
very
well received.
-- RBarryYoung
,
(302)375-0451
blog:
MovingSQL.com
, Twitter:
@RBarryYoung
Proactive
Performance Solutions, Inc.
"Performance is our middle name."
Post #613038
« Prev Topic
|
Next Topic »
126 posts, Page 2 of 13
««
1
2
3
4
5
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.