March 15, 2006 at 7:36 am
I have 2 fields address1,address2, How can i get address1 if address2 has null in it
March 15, 2006 at 7:49 am
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
March 15, 2006 at 8:09 am
I need all address2 value and if there is null in address2 then display address1 value in place of that
March 15, 2006 at 8:18 am
for instance my result set shud be in this way.
address1 address2 Result
aaaa xxxx xxxx
bbbb bbbb
cccc yyyy yyyy
March 15, 2006 at 8:35 am
Try a CASE statement:
SELECT Result =
CASE WHEN address2 IS NULL
THEN address1
ELSE address2
END
FROM tablename
-SQLBill
March 15, 2006 at 9:53 am
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