select

  •  I have 2 fields address1,address2, How can i get address1 if address2 has null in it

  • If you mean how do you return all rows where address2 is null, you can do something like:

    SELECT address1
    FROM yourTable
    WHERE address2 IS NULL

    If you mean how can you get address1, even if address2 has no value, address2 should have no impact on address1. For instance:

    SELECT address1, address2
    FROM yourTable

    Yes, you'll have null values for some of the entries in the address2 column, but you'll still get the address1 column just fine.

    K. Brian Kelley
    @kbriankelley

  • I need all address2 value and if there is null in address2 then display address1 value in place of that

  • for instance my result set shud be in this way.

    address1    address2         Result

    aaaa            xxxx             xxxx

    bbbb                               bbbb

    cccc            yyyy             yyyy

  • Try a CASE statement:

    SELECT Result =

    CASE WHEN address2 IS NULL

    THEN address1

    ELSE address2

    END

    FROM tablename

    -SQLBill

  • You can do this too...

    SELECT ISNULL(address2, address1) AS Result FROM tablename

    Or...

    SELECT COALESCE(address2, address1) AS Result FROM tablename

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

Viewing 6 posts - 1 through 5 (of 5 total)

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