Help with a tricky query

  • lee rite (3/3/2011)


    ColdCoffee (3/3/2011)


    SELECT GUID

    FROM #T

    GROUP BY GUID

    HAVING COUNT( DISTINCT CompanyName) = 1

    Thanks ColdCoffee! I think you nailed it. Your query selects all companies that never changed their name. I think I can work with that!

    Thank you very much, guys!

    Spoke too soon. It works for only those companies that dont have any NULLs.

  • ColdCoffee (3/3/2011)


    SELECT GUID

    FROM #T

    GROUP BY GUID

    HAVING COUNT( DISTINCT CompanyName) = 1

    That'll get the ones that haven't changed. Change it from equals 1 to greater than 1 and you'll get the ones that have changed.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • lee rite (3/3/2011)


    lee rite (3/3/2011)


    ColdCoffee (3/3/2011)


    SELECT GUID

    FROM #T

    GROUP BY GUID

    HAVING COUNT( DISTINCT CompanyName) = 1

    Thanks ColdCoffee! I think you nailed it. Your query selects all companies that never changed their name. I think I can work with that!

    Thank you very much, guys!

    Spoke too soon. It works for only those companies that dont have any NULLs.

    Just add a WHERE clause to remove the NULL rows! Like

    SELECT GUID

    FROM #T

    WHERE CompanyName IS NOT NULL

    GROUP BY GUID

    HAVING COUNT( DISTINCT CompanyName) = 1

  • ColdCoffee (3/3/2011)


    lee rite (3/3/2011)


    lee rite (3/3/2011)


    ColdCoffee (3/3/2011)


    SELECT GUID

    FROM #T

    GROUP BY GUID

    HAVING COUNT( DISTINCT CompanyName) = 1

    Thanks ColdCoffee! I think you nailed it. Your query selects all companies that never changed their name. I think I can work with that!

    Thank you very much, guys!

    Spoke too soon. It works for only those companies that dont have any NULLs.

    Just add a WHERE clause to remove the NULL rows! Like

    SELECT GUID

    FROM #T

    WHERE CompanyName IS NOT NULL

    GROUP BY GUID

    HAVING COUNT( DISTINCT CompanyName) = 1

    Thanks again! I think I'm done! I really appreciate all the help!

  • lee rite (3/3/2011)


    Thanks again! I think I'm done! I really appreciate all the help!

    Will i be getting a Samsung Focus for this help , mate ?? :hehe:

  • ColdCoffee (3/3/2011)


    lee rite (3/3/2011)


    Thanks again! I think I'm done! I really appreciate all the help!

    Will i be getting a Samsung Focus for this help , mate ?? :hehe:

    I will probably get a thank you from my manager for completing this project that I will make sure to forward to you. I will also mention to him that a lot of credit should be given to ColdCoffee. So you are getting a thank you and a recognition. Isn't it so much better than Samsung Focus? :hehe:

  • lee rite (3/3/2011)


    ColdCoffee (3/3/2011)


    lee rite (3/3/2011)


    Thanks again! I think I'm done! I really appreciate all the help!

    Will i be getting a Samsung Focus for this help , mate ?? :hehe:

    I will probably get a thank you from my manager for completing this project that I will make sure to forward to you. I will also mention to him that a lot of credit should be given to ColdCoffee. So you are getting a thank you and a recognition. Isn't it so much better than Samsung Focus? :hehe:

    ... about as much as drinking cold coffee... :w00t:

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    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
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • lee rite (3/3/2011)


    ColdCoffee (3/3/2011)


    lee rite (3/3/2011)


    Thanks again! I think I'm done! I really appreciate all the help!

    Will i be getting a Samsung Focus for this help , mate ?? :hehe:

    I will probably get a thank you from my manager for completing this project that I will make sure to forward to you. I will also mention to him that a lot of credit should be given to ColdCoffee. So you are getting a thank you and a recognition. Isn't it so much better than Samsung Focus? :hehe:

    If you tell your manager that you couldn't have gotten this project done without cold coffee, he'll definitely be confused. Probably worth it for the entertainment value.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (3/3/2011)


    lee rite (3/3/2011)


    ColdCoffee (3/3/2011)


    lee rite (3/3/2011)


    Thanks again! I think I'm done! I really appreciate all the help!

    Will i be getting a Samsung Focus for this help , mate ?? :hehe:

    I will probably get a thank you from my manager for completing this project that I will make sure to forward to you. I will also mention to him that a lot of credit should be given to ColdCoffee. So you are getting a thank you and a recognition. Isn't it so much better than Samsung Focus? :hehe:

    If you tell your manager that you couldn't have gotten this project done without cold coffee, he'll definitely be confused. Probably worth it for the entertainment value.

    I have new expectations of his manager going down to the break room and cutting the plug on the coffee machine's heating plates now...


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Craig Farrell (3/3/2011)


    GSquared (3/3/2011)


    lee rite (3/3/2011)


    ColdCoffee (3/3/2011)


    lee rite (3/3/2011)


    Thanks again! I think I'm done! I really appreciate all the help!

    Will i be getting a Samsung Focus for this help , mate ?? :hehe:

    I will probably get a thank you from my manager for completing this project that I will make sure to forward to you. I will also mention to him that a lot of credit should be given to ColdCoffee. So you are getting a thank you and a recognition. Isn't it so much better than Samsung Focus? :hehe:

    If you tell your manager that you couldn't have gotten this project done without cold coffee, he'll definitely be confused. Probably worth it for the entertainment value.

    I have new expectations of his manager going down to the break room and cutting the plug on the coffee machine's heating plates now...

    Haha! Maybe I shouldn't mention ColdCoffee....OR...maybe I should ask ColdCoffee to change his name to HotLunch or something like that :w00t:

  • Just be glad he goes by ColdCoffee. Think how much worse it would be if you had to say the day was saved by FlatRootbeer, or SpoiledMilk.... WarmBeer might at least make more sense than those, but would raise other questions....

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Lol :w00t: !! my nickname is derived from a bitter experience by drinkng ColdCoffee, but that led to the formation of a set of close friends for me; so, me changing to HotLunch would never occur 🙂 but nonetheless, as Gus points out, Cold Coffee is much better than the Root Beers or Ginger Ales 😛 :hehe:

  • ColdCoffee (3/3/2011)


    Lol :w00t: !! my nickname is derived from a bitter experience by drinkng ColdCoffee, but that led to the formation of a set of close friends for me; so, me changing to HotLunch would never occur 🙂 but nonetheless, as Gus points out, Cold Coffee is much better than the Root Beers or Ginger Ales 😛 :hehe:

    Ah c'mon! Change it to "Steak Dinners" for a while. Then when this guy tells his boss what he needs in order to get projects done, he's got a chance at something nice! :w00t:

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (3/4/2011)


    ColdCoffee (3/3/2011)


    Lol :w00t: !! my nickname is derived from a bitter experience by drinkng ColdCoffee, but that led to the formation of a set of close friends for me; so, me changing to HotLunch would never occur 🙂 but nonetheless, as Gus points out, Cold Coffee is much better than the Root Beers or Ginger Ales 😛 :hehe:

    Ah c'mon! Change it to "Steak Dinners" for a while. Then when this guy tells his boss what he needs in order to get projects done, he's got a chance at something nice! :w00t:

    Or at least to "WellDeservedRaiseandBonus"

Viewing 14 posts - 16 through 29 (of 29 total)

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