SQL Server 2008: SQL Query using IF in columns
I have a colum like this in my query with SQL Server 2008
CONVERT(VARCHAR(10),C.HACIZ_TAR,103) AS 'HACİZ TARİHİ'
In this column, some data value is 01/01/1900
.
What i want is if this column's value 01/01/1900
, then get null
instead of 01/01/1900
How can i do that?
This is full select part in my sql
SELECT B.HESAP_NO, A.TEKLIF_NO1 + '/' + A.TEKLIF_NO2 AS 'TEKLIF',
B.MUS_K_ISIM, CONVERT(VARCHAR(10),A.ISL_TAR,103) AS 'TARIH',
SUM(ISNULL(CAST(A.ODENEN_ANAPARA AS FLOAT),0)+ISNULL(CAST(A.FAIZ AS FLOAT),0)+
ISNULL(CAST(A.BSMV AS FLOAT),0)+ISNULL(CAST(A.GECIKME_FAIZ AS FLOAT),0)+
ISNULL(CAST(A.GECIKME_BSMV AS FLOAT),0)) AS 'YATAN',
(CASE WHEN B.DOVIZ_KOD = 21 THEN 'EUR' WHEN B.DOVIZ_KOD = 2 THEN 'USD' WHEN B.DOVIZ_KOD = 1 THEN 'TL' END) AS 'KUR',
D.AVUKAT, CONVERT(VARCHAR(10),C.ICRA_TAR,103) AS 'İCRA TARİHİ', CONVERT(VARCHAR(10),C.HACIZ_TAR,103) AS 'HACİZ TARİ开发者_开发技巧Hİ'
Use the NULLIF
statement:
nullif(CONVERT(VARCHAR(10),C.HACIZ_TAR,103), '01/01/1900') AS 'HACİZ TARİHİ'
not sure about how conversion works on SQL Server but try this:
(CASE
WHEN CONVERT(VARCHAR(10), A.ISL_TAR, 103) = '01/01/1900' THEN
NULL
ELSE CONVERT(VARCHAR(10), A.ISL_TAR, 103)
END) AS 'TARIH'
精彩评论