Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Expert,


Database :: ms sql server database

A table with the following fields

Table Trial

idno name first_date second_date
--------------------------------------
001 ivy 22/12/2017 17/11/2017
002 jon 14/03/2017
003 pet 15/09/2017



Request

A select statement which will select either field first_date if second_date is null else
it should select second_date


How do you accomplish this in ms sql server select statement ?


Thanks

What I have tried:

Its an on going development, looked at earlier codes no sample code
Posted
Updated 10-Jan-18 7:56am
v2

1 solution

check this SQL Server COALESCE() Function[^]
SQL
select idno, name, COALESCE (first_date ,second_date) as DateColumn from YourTableName
 
Share this answer
 
v2
Comments
Maciej Los 10-Jan-18 13:56pm    
+5
Karthik_Mahalingam 10-Jan-18 21:46pm    
Thank you Maciej

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900