I want to check for data but ignore it if it's null or empty. Currently the query is as follows...
Select
Coalesce(listing.OfferText, company.OfferText, '') As Offer_Text,
from tbl_directorylisting listing
Inner Join tbl_companymaster company
On listing.company_id= company.company_id
But I want to get company.OfferText if listing.Offertext is an empty string, as well as if it's null.
What's the best performing solution?
Use the LEN function to check for null or empty values. You can just use LEN(@SomeVarcharParm) > 0. This will return false if the value is NULL, '', or ' '. This is because LEN(NULL) returns NULL and NULL > 0 returns false. Also, LEN(' ') returns 0. See for yourself run:
Here's a solution, but I don't know if it's the best....
this syntax :
worked for me in Microsoft SQL Server 2008 (SP3)
You can use
ISNULL
and check the answer against the known output: