SOME rows

  • Comments posted to this topic are about the item SOME rows

  • Thanks for question Steve.Never used this function so learnt new funtion 🙂

    --rhythmk
    ------------------------------------------------------------------
    To post your question use below link

    https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
    🙂

  • Thank you for the post, Steve, very good one.

    At first, I marked the"1" choice, but didn't feel it right, then thought it will be true for all rows as the comparison was been made with static string '2014' then changed to "8". 🙂 (I used it once so I vaguely remembered and had to refer msdn to make myself clear)

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • Great question. Aside from exam questions on MS certification, I have never ever encountered this in code and never used it myself.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • This was removed by the editor as SPAM

  • Are there any circumstances where using SOME would be preferable to the equivalent with EXISTS?

  • Never used Some fn b4, thanx for sharing the question & info 🙂

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • Just encountered it - for the very first time in my career - in the generated query of a BO report.

    When you select a parameter for a date (e.g. December 2014) it generated a WHERE clause like this:

    WHERE month <= ANY (SELECT month FROM dbo.Calendar WHERE month = '2014-12')

    I always wonder what kind of idiots where SQL generators for reporting tools.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Nice QotD Steve!, the next question do it with clause "ANY"

    😛

  • Great question, and I nearly clicked 0 because '2014' = True SHOULD fail, but doesn't in SQL.

  • Good one Steve, I clicked the 1 and was about to submit when my eyes landed on the 500 and the light bulb clicked on..... 500 > 200 and = 2014 means Steve is being sneaky - as usual!

  • I've never used it or encountered it either, so I learned something new. Thanks!

  • Good introduction Steve! I've never used the SOME function before.

    I think it's also pertinent to point out that the reason all 8 rows returned was because of the use of a literal for the comparison and of course the literal didn't change for all eight rows. Had the literal been replaced with a column reference like this:

    SELECT

    CustomerID

    FROM

    sales

    WHERE Salesyear = SOME (SELECT salesyear FROM sales WHERE amount > 200);

    Then it would have resulted in only four rows returned (for those matching the Salesyear 2014).

    I must admit some curiosity along with several others in wondering what benefits this presents over the EXISTS clause.

  • Brian Hibbert (1/29/2015)


    Great question, and I nearly clicked 0 because '2014' = True SHOULD fail, but doesn't in SQL.

    So this is the real answer. Much better than the provided link in explaining why 8 was the correct answer.

  • doug.davidson (1/29/2015)


    Brian Hibbert (1/29/2015)


    Great question, and I nearly clicked 0 because '2014' = True SHOULD fail, but doesn't in SQL.

    So this is the real answer. Much better than the provided link in explaining why 8 was the correct answer.

    I think I'm not quite understanding what SOME (or Any) actually does.

    A quick read of the BOL says the return type is Boolean, but it's not quite as simple as that. SOME isn't a standalone function as I initially thought, it's more like a modifier to the comparison operators.

Viewing 15 posts - 1 through 15 (of 33 total)

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