Null comparision using sql

  • Hi,

    I need to compare sql table field . if field is not null concatenate 'BY: thenmozhi' , if field is null i need to return empty field ..

    how i will write sql query

    Thanks

  • You cold use the COALESCE function for example:

    DECLARE @v-2 VARCHAR(5)

    SET @v-2 = NULL

    --returns a blank ---returns the asterik

    SELECT COALESCE(@v,' '),COALESCE(@v, '*')

    A better example:

    DECLARE @v-2 VARCHAR(5)

    DECLARE @W VARCHAR(5)

    SET @W ='B'

    SET @v-2 = NULL

    SELECT COALESCE(@v,' '),COALESCE(@W, ' ')

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Hi bitbucket,

    Thanks a lot... its working...

    🙂

  • sthenmozhi14 (11/5/2011)


    Hi bitbucket,

    Thanks a lot... its working...

    🙂

    Your welcome and thanks for letting me know ....

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

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