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?
In SQL Server 2012 you have
IIF
, e.g you can use it likeThe same way you can check if field is empty.
I know this is an old thread but I just saw one of the earlier posts above and it is not correct.
If you are using LEN(...) to determine whether the field is NULL or EMPTY then you need to use it as follows:
[Column_name] > ' ' excludes Nulls and empty strings. There is a space between the single quotes.
I think this:
is the most elegant solution.
And to break it down a bit in pseudo code:
To prevent the records with
Empty
orNull
value in SQL resultwe can simply add
..... WHERE Column_name != '' or 'null'