Nov 19, 2013 #1 staceyn Technical User Nov 19, 2004 107 US Hello, I am trying to figure out how to write the following query in SQL if anyone can help Use field A if not blank othrewise use field B, if field B is blank print "N/A" Thanks
Hello, I am trying to figure out how to write the following query in SQL if anyone can help Use field A if not blank othrewise use field B, if field B is blank print "N/A" Thanks
Nov 19, 2013 #2 bborissov Programmer May 3, 2005 5,167 BG Code: SELECT COALESCE(NULLIF(FieldA,''), NULLIF(FieldB,''), 'N/A') FROM YourTable th fieldA or FieldB can not be empty, just NULL, then there is no need to use NULLIF() function. Borislav Borissov VFP9 SP2, SQL Server Upvote 0 Downvote
Code: SELECT COALESCE(NULLIF(FieldA,''), NULLIF(FieldB,''), 'N/A') FROM YourTable th fieldA or FieldB can not be empty, just NULL, then there is no need to use NULLIF() function. Borislav Borissov VFP9 SP2, SQL Server
Nov 19, 2013 Thread starter #3 staceyn Technical User Nov 19, 2004 107 US Thanks so much will give this a try Upvote 0 Downvote