| Author |
Topic  |
|
|
gagani
Yak Posting Veteran
84 Posts |
Posted - 06/28/2012 : 05:33:01
|
customerid forename1 surname1 forename2 surname2 101 gordon carolyn tattersall
if there is nothing in surname1, then i should get the output as surname2
from the above table, i should get the output as
tattersall |
|
|
aakcse
Aged Yak Warrior
India
517 Posts |
Posted - 06/28/2012 : 05:36:34
|
try using case statement to get the result
-Neil |
 |
|
|
gagani
Yak Posting Veteran
84 Posts |
Posted - 06/28/2012 : 05:40:19
|
I am unable to get it right with the case. could you please write the query.
many thanks |
 |
|
|
xhostx
Constraint Violating Yak Guru
USA
261 Posts |
Posted - 06/28/2012 : 08:51:09
|
quote: Originally posted by gagani
customerid forename1 surname1 forename2 surname2 101 gordon carolyn tattersall
if there is nothing in surname1, then i should get the output as surname2
from the above table, i should get the output as
tattersall
can you explain more please?
-------------------------- Get rich or die trying -------------------------- |
 |
|
|
anchoredwisdom
Starting Member
20 Posts |
Posted - 06/29/2012 : 09:44:49
|
| SELECT CUSTOMERID,FORENAME1,SURNAME`,FORENAME2, DECODE(SURNAME2,NULL,SURNAME1,SURNAME2 END) SURNAME2 FROM TABLE1 |
 |
|
|
xhostx
Constraint Violating Yak Guru
USA
261 Posts |
Posted - 06/29/2012 : 10:04:10
|
quote: Originally posted by anchoredwisdom
SELECT CUSTOMERID,FORENAME1,SURNAME`,FORENAME2, DECODE(SURNAME2,NULL,SURNAME1,SURNAME2 END) SURNAME2 FROM TABLE1
I think your select is an Oracle query!!
if so, Please try NVL or NVL2 functions.
if you are using SQL Server try this: SELECT CUSTOMERID,FORENAME1,SURNAME,FORENAME2, case when SURNAME1 is null then SURNAME2 else SURNAME1 end as name_column FROM TABLE1
Remember that this is a SQL server Forum.
Luck
-------------------------- Get rich or die trying -------------------------- |
Edited by - xhostx on 06/29/2012 10:08:02 |
 |
|
| |
Topic  |
|