COALESCE

  • sqlnaive

    SSCoach

    Points: 17435

    Comments posted to this topic are about the item COALESCE

  • ksatpute123

    Hall of Fame

    Points: 3325

    Easy one. Thanks.

  • Raghavendra Mudugal

    SSChampion

    Points: 10658

    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

  • Dscheypie

    Default port

    Points: 1484

    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.

  • Pavel Bakunovich

    SSC Veteran

    Points: 297

    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.

  • Andrew Watson-478275

    SSCarpal Tunnel

    Points: 4472

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

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

  • Mr. Kapsicum

    SSCertifiable

    Points: 6128

    very easy one 🙂

  • sqlnaive

    SSCoach

    Points: 17435

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

  • Koen Verbeeck

    SSC Guru

    Points: 258905

    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

  • twin.devil

    SSC-Insane

    Points: 22208

    nice weekend question 🙂

  • Tee Time

    Hall of Fame

    Points: 3663

    Good one, thanks!

  • Dscheypie

    Default port

    Points: 1484

    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.

  • psingla

    Hall of Fame

    Points: 3840

    Nice question,Normally asked in interviews

    Pramod
    SQL Server DBA | MCSE SQL Server 2012/2014

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

  • Dana Medley

    SSCertifiable

    Points: 6764

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



    Everything is awesome!

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

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