COALESCE

  • Comments posted to this topic are about the item COALESCE

  • Easy one. Thanks.

  • Good one, thank you for the post.

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

  • This was removed by the editor as SPAM

  • I would have had slightly more troubles, if the INT data type would've been inserted first.

    Because in the first try I thought that the numeric data type would set the returned data type which is definitely wrong.

    Thank you for the question!

    ________________________________________________________
    If you set out to do something, something else must be done first.

  • Dscheypie (9/20/2013)


    I would have had slightly more troubles, if the INT data type would've been inserted first.

    Because in the first try I thought that the numeric data type would set the returned data type which is definitely wrong.

    Thank you for the question!

    Statement, when int is first

    SELECT COALESCE(Col2, Col1) AS 'FirstNotNull' FROM dbo.T_TEST

    will have the same output(I mean type:), not numbers), because returned data type is defined expression with the highest data type precedence.

  • As well as the reference given, this one should be included too:

    http://msdn.microsoft.com/en-us/library/ms190309(v=sql.105).aspx

  • very easy one 🙂

  • Andrew Watson-478275 (9/20/2013)


    As well as the reference given, this one should be included too:

    http://msdn.microsoft.com/en-us/library/ms190309(v=sql.105).aspx

    Thanks for referring this link Andrew. I had planned to include this link as additional info but somehow managed to miss it. 🙂

  • Very nice question for a Friday, thanks.

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

  • nice weekend question 🙂

  • Good one, thanks!

  • Pavel Bakunovich (9/20/2013)


    Dscheypie (9/20/2013)


    I would have had slightly more troubles, if the INT data type would've been inserted first.

    Because in the first try I thought that the numeric data type would set the returned data type which is definitely wrong.

    Thank you for the question!

    Statement, when int is first

    SELECT COALESCE(Col2, Col1) AS 'FirstNotNull' FROM dbo.T_TEST

    will have the same output(I mean type:), not numbers), because returned data type is defined expression with the highest data type precedence.

    Oh, this is even easier. Good idea, Pavel! Simple, yes!

    ________________________________________________________
    If you set out to do something, something else must be done first.

  • Nice question,Normally asked in interviews

    Pramod
    SQL Server DBA | MCSE SQL Server 2012/2014

    in.linkedin.com/in/pramodsingla/
    http://pramodsingla.wordpress.com/

  • Easy one to end the week on. 😀 Thanks for the question!



    Everything is awesome!

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

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