用空白替换'NULL'

时间:2018-10-23 14:19:34

标签: sql-server tsql

我有此选择

SELECT 
    [DtData] AS Data, [CdTelefono] AS Telefono,  
    [DsServizio] AS Servizio, [TotAvgDurata] AS DurataMedia, 
    [TotAvgAttesa] AS MediaTempoAttesa, [TotNumTime] AS NumVolte, 
    [CdQuartoDiAnno] AS Trimestre, 
    [CallbackDateTimeZone1] AS DataSchedulazione,
    CASE
       WHEN CallStatusZone1 = 'C' THEN 'Contattato' 
       WHEN CallStatusZone1 = 'M' THEN 'Max Tentativi' 
       WHEN CallStatusZone1 = 'R' THEN 'Rischedulato' 
       ELSE CallStatusZone1 
    END AS Stato,
    Cd_Risposta1_DTMF AS Risp1, Cd_Risposta2_DTMF AS Risp2, 
    Cd_Risposta3_DTMF AS Risp3, Cd_Risposta4_DTMF AS Risp4, 
    Fg_Partecipazione AS Stato
FROM
    ([CallCenter].[dbo].[TLC_ANAGRAFE_QUESTIONARIO] AG 
INNER JOIN
    ICM10IPCC10.prod_baA.dbo.DL_5040_5041 DL ON AG.CdTelefono = DL.Phone01)    
LEFT OUTER JOIN 
    ICM10IPCC10.Campagne.dbo.TLC_QUESTIONARIO_CUSTOMER_IVR IVR ON AG.CdTelefono = IVR.Cd_Phone01

,我想知道如何在没有可供选择的数据的空白处替换'NULL',

谢谢。

2 个答案:

答案 0 :(得分:2)

使用coalesce函数将返回第一个非null值,因此,如果在这种情况下您的列值为null,则它将返回空白字符串

select coalesce(col1,' ') from table

答案 1 :(得分:2)

解决方案2:

T-SQL:

SELECT NVL(Column_to_check,'') FROM SomeTable

PL / SQL:

NVL2(Column_to_check, value_if_NOT_null, value_if_null )

如果要从Column_to_check中返回其他值,也可以使用NVL2,如下所示:

:: Set primary and alternate DNS for IPv4 on Windows Server 2000/2003/2008 & 
:: Windows XP/Vista/7
@ECHO OFF
SETLOCAL EnableDelayedExpansion

netsh interface ipv4 set dns "Local Area Connection" static 8.8.8.8
netsh interface ipv4 add dns "Local Area Connection" 8.8.4.4 index=2

:EOF