Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gagani
Posting Yak Master
112 Posts |
Posted - 2012-06-28 : 05:33:01
|
| customerid forename1 surname1 forename2 surname2101 gordon carolyn tattersallif there is nothing in surname1, then i should get the output as surname2from the above table, i should get the output astattersall |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2012-06-28 : 05:36:34
|
| try using case statement to get the result-Neil |
 |
|
|
gagani
Posting Yak Master
112 Posts |
Posted - 2012-06-28 : 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
277 Posts |
Posted - 2012-06-28 : 08:51:09
|
quote: Originally posted by gagani customerid forename1 surname1 forename2 surname2101 gordon carolyn tattersallif there is nothing in surname1, then i should get the output as surname2from the above table, i should get the output astattersall
can you explain more please?--------------------------Get rich or die trying-------------------------- |
 |
|
|
anchoredwisdom
Starting Member
22 Posts |
Posted - 2012-06-29 : 09:44:49
|
| SELECT CUSTOMERID,FORENAME1,SURNAME`,FORENAME2, DECODE(SURNAME2,NULL,SURNAME1,SURNAME2 END) SURNAME2 FROM TABLE1 |
 |
|
|
xhostx
Constraint Violating Yak Guru
277 Posts |
Posted - 2012-06-29 : 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_columnFROM TABLE1Remember that this is a SQL server Forum.Luck--------------------------Get rich or die trying-------------------------- |
 |
|
|
|
|
|
|
|