Cross Tabs and Pivots, Part 1 – Converting Rows to Columns

  • Here is a previous discussion that shows how to do multiple aggregations in a single pivot. We went back and forth on the various forms of pivot/cross-tab and which was better/faster/easier etc...

    http://www.sqlservercentral.com/Forums/Topic521489-338-1.aspx

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Jeffrey Williams (4/13/2009)


    Here is a previous discussion that shows how to do multiple aggregations in a single pivot. We went back and forth on the various forms of pivot/cross-tab and which was better/faster/easier etc...

    http://www.sqlservercentral.com/Forums/Topic521489-338-1.aspx

    THAT's the one... thanks Jeffrey.

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Paul White (4/13/2009)


    Jeff Moden (4/12/2009)


    Oh, and have you enabled CLR yet and learnt C#? :laugh:

    Heh... no, not yet, Paul.

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • You are welcome - I remembered the conversation and then it was just a matter of searching for a question that was posted by Jeff Moden. Since that particular individual does not actually start a lot of threads, it was fairly easy to find. 😛

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Jeff Moden (4/13/2009)


    Paul White (4/13/2009)


    Jeff Moden (4/12/2009)


    Oh, and have you enabled CLR yet and learnt C#? :laugh:

    Heh... no, not yet, Paul.

    And why should you? We should all agree that better SQL is the answer. We all won't, but we should.

    OK, I know that using the CLR means that I can write good post-processing routines that will present uniform result to any front end. No front end is any good if the query times out or clogs the whole server.

    ATBCharles Kincaid

  • Charles Kincaid (4/17/2009)


    Jeff Moden (4/13/2009)


    Paul White (4/13/2009)


    Jeff Moden (4/12/2009)


    Oh, and have you enabled CLR yet and learnt C#? :laugh:

    Heh... no, not yet, Paul.

    And why should you? We should all agree that better SQL is the answer. We all won't, but we should.

    OK, I know that using the CLR means that I can write good post-processing routines that will present uniform result to any front end. No front end is any good if the query times out or clogs the whole server.

    I agree. Learning something new is just a form of grandstanding. It's a crutch for people who really haven't mastered what their already using 🙂

    www.beyondsql.blogspot.com

  • steve dassin (4/17/2009)


    I agree. Learning something new is just a form of grandstanding. It's a crutch for people who really haven't mastered what their already using 🙂

    Then learn something new, Steve. Learn to make a point without displaying a condescending and arrogant attitude and without words that drip with sarcasm. You're a smart man, but no one will listen to you because of your in-your-face lack of manners.

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Charles Kincaid (4/17/2009)


    Jeff Moden (4/13/2009)


    Paul White (4/13/2009)


    Jeff Moden (4/12/2009)


    Oh, and have you enabled CLR yet and learnt C#? :laugh:

    Heh... no, not yet, Paul.

    And why should you? We should all agree that better SQL is the answer. We all won't, but we should.

    OK, I know that using the CLR means that I can write good post-processing routines that will present uniform result to any front end. No front end is any good if the query times out or clogs the whole server.

    As irritating as his mannerisms are to me, I actually do agree to the basic principle that Steve Dassin has been trying to convey. "Better SQL" should also include better, faster, and more correct functionality in the database engine itself even if they never do come close to what he calls a "true relational database". I'd settle for peeling-a-potato-at-a-time progress, but it sometimes appears that the people who make database engines are more concerned with what color the potato bag is. People shouldn't have to write a CLR or even a Tally table to do simple tasks like splitting a bloody parameter.

    Still, I hope they don't fix things too soon... I've made a lot of money with things like the Tally table and I'm not quite ready to retire, yet. I also really enjoy the challenge of building T-SQL-Only solutions to make up for some of the inadequacies of the language. It's also a lot of fun to watch people lose their cool and ineffectively rant about those inadequacies. 😉

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Charles Kincaid (4/17/2009)


    And why should you? We should all agree that better SQL is the answer. We all won't, but we should.

    OK, I know that using the CLR means that I can write good post-processing routines that will present uniform result to any front end. No front end is any good if the query times out or clogs the whole server.

    Hey Charles,

    I object to your use of the word 'we' there -- unless I can apply somewhere for a special exemption to have independent opinions please? I know it's awkward of me, but it's a luxury I've kinda become used to 😉

    I would certainly vote for 'better SQL' - well who would want worse? I think the global 'we' might agree on that at least...:-)

    It saddens me slightly (though I am very sensitive heh) that so many see CLR as being in competition with SQL. Is it not just a natural and useful extension to SQL Server, which is sometimes the only way to get a job done?

    Adding the ability to call managed code offers all sorts of new possibilities to the database developer. It's certainly not compulsory to use CLR, and my first instinct is always to start by looking for a solution which does not use it. That's simply because of the extra effort involved, and the need to switch development environments and languages.

    I'm determined to keep this post short, so I'll just point the interested reader to http://msdn.microsoft.com/en-us/library/ms345136(SQL.90).aspx for a good summary of why CLR is a useful addition to SQL Server.

    So much more than just 'post-processing'...:cool:

    Cheers

    Paul

  • steve dassin (4/17/2009)


    I agree. Learning something new is just a form of grandstanding. It's a crutch for people who really haven't mastered what their already using 🙂

    Hey Steve,

    Just so you know, I found your post to be quite amusing!

    Quite clever, even. 🙂

    Not seen anything from you previously, so I can't say whether Jeff's comments are fair or unfair; though I tend to attach weight to Jeff's words, so...keeping an open mind.

    Learning is good. The day I stop learning, I will know I died during the night.

    Paul

  • Jeff Moden (4/17/2009)


    Then learn something new, Steve. Learn to make a point without displaying a condescending and arrogant attitude and without words that drip with sarcasm. You're a smart man, but no one will listen to you because of your in-your-face lack of manners.

    Refreshing to read an obviously honest and from-the-heart post, which hasn't gone through the forum "nicey-nicey, self-effacing to a fault" filter which is so prevalent on SSC.

  • Jeff Moden (4/17/2009)


    "Better SQL" should also include better, faster, and more correct functionality in the database engine itself...

    Agreed. MS should direct most of their effort to the core product. Expending effort there ought to be a much higher priority than developing things like Notification Services, for example! IMHO, that is.

    Jeff Moden (4/17/2009)


    I'd settle for peeling-a-potato-at-a-time progress, but it sometimes appears that the people who make database engines are more concerned with what color the potato bag is.

    Beautifully put, and I could not agree more. Even at gunpoint.

    Jeff Moden (4/17/2009)


    People shouldn't have to write a CLR or even a Tally table to do simple tasks like splitting a bloody parameter.

    No, you're right. The piggin' parameter shouldn't need splitting in the first place. I blame the application developers :laugh:

    Seriously, we do have the tools to split a parameter - CHARINDEX and so on. Performance is only an issue with very large strings or lots of them - which is surely the exception rather than the rule. It seems quite sensible that a custom (CLR or Tally) solution is required here for optimal performance.

    If you add good string manipulation routines to T-SQL, where would you stop? Feeping creaturitis would eventually result in incorporating a good chunk of the common language runtime anyway...see where I'm going?

    Jeff Moden (4/17/2009)


    Still, I hope they don't fix things too soon... I've made a lot of money with things like the Tally table and I'm not quite ready to retire, yet. I also really enjoy the challenge of building T-SQL-Only solutions to make up for some of the inadequacies of the language. It's also a lot of fun to watch people lose their cool and ineffectively rant about those inadequacies. 😉

    It's nice that you are rich, though maybe not so great to enjoy watching people lose their cool...

    Beware the risk of coming off as arrogant, condescending, and sarcastic...:laugh:

  • Paul White (4/18/2009)


    Beware the risk of coming off as arrogant, condescending, and sarcastic...:laugh:

    Oh... unlike some on this thread, I'm well aware of those risks. But, I'm also human... I don't usually start a "fight" with someone using such tactics, but I have been known to respond in kind. The thread on Barry's recent article is an example of that... some of those folks that insist that you should always program to the lowest denominator and that justify inappropriate usage of cursors because they're supposedly more intuitive, just need a good punch in the nose and it's very difficult to suppress those urges especially when they've attempted to do the same.

    It's nice that you are rich, though maybe not so great to enjoy watching people lose their cool...

    Heh... if I were rich, I wouldn't need to work (although I probably still would). The reason why I enjoy watching people lose their cool on occasion is because of the responses that they get. Those responses teach me more about the human element and how to deal with it because I'm not really a big fan of the human element especially as some portray it.

    A good example would be what you and I recently went through... because of the written-only format and the lack of tonal inflection, I didn't know if the term "brute-force" was being directed as a personal slam or a mere observation of code fact... unlike some, I asked for clarification and was very satisfied with the answer. Others say things that are just freakin' rude. Things like "I hope I don't run into cerebral cement" pretty much says "I hope you're not stupid" and are both totally inflamatory and absolutely unnecessary in trying to make a point even if it is an outstanding point.

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Paul White (4/18/2009)


    Jeff Moden (4/17/2009)


    Then learn something new, Steve. Learn to make a point without displaying a condescending and arrogant attitude and without words that drip with sarcasm. You're a smart man, but no one will listen to you because of your in-your-face lack of manners.

    Refreshing to read an obviously honest and from-the-heart post, which hasn't gone through the forum "nicey-nicey, self-effacing to a fault" filter which is so prevalent on SSC.

    Heh... like I said... I'm not a big fan of the human element as some portray it. 😀 And, I thought I was being "nicey-nicey" in that case... it's no where close to what I was thinking. :hehe:

    --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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Good answers, Jeff!

    Amusing too.

    Keep up the good work 🙂

    Paul

Viewing 15 posts - 136 through 150 (of 243 total)

You must be logged in to reply to this topic. Login to reply