SET the results

  • Comments posted to this topic are about the item SET the results

  • new thing added in my database about "SET" statement

    Manik
    You cannot get to the top by sitting on your bottom.

  • Nice one, thanks Steve.
    Personal preference to use SELECT to assign values to variables.

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • Oh silly me! I was so focused on the whole principle that order is not guaranteed without an ORDER BY clause that I didn’t notice the use of SET instead of SELECT. I’ll definitely need to pay attention to these more carefully!

    Tricky one Steve, ya got me! 😛

  • Good Question.
    I was thinking to myself that not enough information was provided about the table structure to answer - since there is no guaranteed order, but we know how the engine behaves. I totally missed the SET statement.

  • This was one that surprised me as well. I didn't realize there was that much difference between SET/SELECT.

  • Aaron N. Cutshall - Tuesday, January 2, 2018 4:46 AM

    Oh silly me! I was so focused on the whole principle that order is not guaranteed without an ORDER BY clause that I didn’t notice the use of SET instead of SELECT. I’ll definitely need to pay attention to these more carefully!Tricky one Steve, ya got me! 😛

    Me 2, I was going down the 'its a heap, it has no imposed order on it' path.

  • ManicStar - Tuesday, January 2, 2018 9:27 AM

    Aaron N. Cutshall - Tuesday, January 2, 2018 4:46 AM

    Oh silly me! I was so focused on the whole principle that order is not guaranteed without an ORDER BY clause that I didn’t notice the use of SET instead of SELECT. I’ll definitely need to pay attention to these more carefully!Tricky one Steve, ya got me! 😛

    Me 2, I was going down the 'its a heap, it has no imposed order on it' path.

    +1 on that!

    ...

  • Simple and nice - thanks, Steve!

  • I'm glad I'm not the only one that missed the SET as I was thinking SELECT as well. Nice one Steve.

    ----------------------------------------------------

  • The answer is a little confused!
    The statement raises an error, because of incorrect syntax and not because of multiple values assignement. The following statements demonstrate this:
    DECLARE @login VARCHAR(100);

    SET @login = c.FirstName
    FROM dbo.Contacts AS c
    --Incorrect syntax near the keyword 'FROM'.

    SET @login = (SELECT c.FirstName
    FROM dbo.Contacts AS c)
    --Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

  • Carlo Romagnano - Wednesday, January 3, 2018 1:29 AM

    The answer is a little confused!
    The statement raises an error, because of incorrect syntax and not because of multiple values assignement. The following statements demonstrate this:
    DECLARE @login VARCHAR(100);

    SET @login = c.FirstName
    FROM dbo.Contacts AS c
    --Incorrect syntax near the keyword 'FROM'.

    SET @login = (SELECT c.FirstName
    FROM dbo.Contacts AS c)
    --Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

    Well spotted, Carlo

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • Thanks for this very instructive question!

    Happy new year,
    webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • Aaron N. Cutshall - Tuesday, January 2, 2018 4:46 AM

    Oh silly me! I was so focused on the whole principle that order is not guaranteed without an ORDER BY clause that I didn’t notice the use of SET instead of SELECT. I’ll definitely need to pay attention to these more carefully!Tricky one Steve, ya got me! 😛

    Same here.  And I knew the right answer if I had just slowed down.

  • At least, it's reassuring that I wasn't the only one that made that error.

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

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