到目前为止,我用谷歌搜索了几个小时,并尝试了许多不同的东西,但不知何故,与其他人一起工作的东西似乎不适用于我的数据集。
*编辑:DBMS:SQL Server。+ 下面的代码
假设这是数据集:
ID,VALIDFROM,VALIDTO
1,1-1-2012,1-1-1900 00:00:00
2,1-1-2016,1-3-2017 00:00:00
3,1-1-2017,1-3,2018 00:00:00
4,1-1-2017,1-1-1900 00:00:00
5,1-1-2018,1-1-1900 00:00:00
我想将NULL
's 转换为今天的日期,但每当我尝试使用NULLIF
or执行此操作时COALESCE
,SQL 都会返回1-1-1900 00:00:00
.
SELECT
A.CONTRACTLINEID,
A.CONTRACTID AS 'Contract ID',
COALESCE(C.RENTALCOSTTYPEID, 'LEEG') AS 'Component ID',
A.NAME AS 'Component',
A.LINETYPE AS 'Componenttype ID',
B.ENUMITEMLABEL AS 'Componenttype',
A.RENTALOBJECTID AS 'Vastgoed Object ID',
A.VALIDFROM,
--A.VALIDTO, -- 1-1-1900 00:00:00
--COALESCE(A.VALIDTO,Sysdate()) AS VALIDTO, -- ERROR
--COALESCE(A.VALIDTO,GETDATE()) AS VALIDTO, -- 1-1-1900 00:00:00
--COALESCE(A.VALIDTO,CURRENT_DATE) AS VALIDTO, -- ERROR
--NULLIF(A.VALIDTO,GETDATE()) AS VALIDTO, -- 1-1-1900 00:00:00
--NULLIF(A.VALIDTO,CURRENT_DATE) AS VALIDTO, -- ERROR
A.COSTSETTLEMENTID,
A.PRICEPERIODID,
A.DATAAREAID,
C.PRICEPRICEID AS 'Prijs ID',
COALESCE(C.PRICE, '0') AS 'Prijs',
C.FROMDATE AS 'Prijs Vanaf Datum',
C.TODATE AS 'Prijs T/m Datum',
COALESCE(C.NAME, 'LEEG') AS 'Component-Prijs',
D.CONTRACTSTATUS AS 'Contract Status'
FROM MRPMCCONTRACTLINES A
LEFT JOIN MRENUMS B ON
B.ENUMITEMVALUE = A.LINETYPE
AND B.ENUMID = 40021
OUTER APPLY
(
SELECT TOP 1 *
FROM MRPMCINVOICELINE C
WHERE C.CONTRACTLINEID = A.CONTRACTLINEID AND C.DATAAREAID = '1'
ORDER BY
C.TODATE DESC
) C
LEFT JOIN PMCCONTRACT D ON
D.CONTRACTID = A.CONTRACTID --Following doesn't do anything so far
UPDATE MRPMCCONTRACTLINES
SET VALIDTO = '01/01/2050'
WHERE VALIDTO IS NULL
OR LTRIM(RTRIM(VALIDTO)) = ''