我想检查数据,但如果它为空或空忽略它。目前查询如下…

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      

但我想找个伴。OfferText如果列表。Offertext是一个空字符串,如果它是null。

最好的解决方案是什么?


当前回答

这里有另一个解决方案:

SELECT Isnull(Nullif(listing.offertext, ''), company.offertext) AS offer_text, 
FROM   tbl_directorylisting listing 
       INNER JOIN tbl_companymaster company 
         ON listing.company_id = company.company_id

其他回答

这里有另一个解决方案:

SELECT Isnull(Nullif(listing.offertext, ''), company.offertext) AS offer_text, 
FROM   tbl_directorylisting listing 
       INNER JOIN tbl_companymaster company 
         ON listing.company_id = company.company_id

防止SQL结果中出现空值或空值的记录

我们可以简单地添加.....WHERE Column_name != "或'null'

[Column_name] > ' '不包含空字符串和空字符串。在单引号之间有一个空格。

这个语法:

SELECT *
FROM tbl_directorylisting listing
WHERE (civilite_etudiant IS NULL)

在Microsoft SQL Server 2008 (SP3)为我工作

要检查变量是否为空,请使用以下命令:

IF LEN(ISNULL(@var, '')) = 0
    -- Is empty or NULL
ELSE
    -- Is not empty and is not NULL