目前正在进行 Oracle 到 T-SQL 语句的转换。这是我要转换的内容:
SELECT USC.USER_ID
,NVL2 (MAX(STREET_1), MAX(STREET_1) || CHR (10), '')
|| NVL2 (MAX(STREET_2), MAX(STREET_2) || CHR (10), '')
|| NVL2 (MAX(STREET_3), MAX(STREET_3) || CHR (10), '')
|| NVL2 (MAX(STREET_4), MAX(STREET_4) || CHR (10), '') AS STREETS
,MAX(ADDR.CITY) AS CITY
,MAX(ADDR.POSTAL_CODE) AS POSTAL_CODE
,MAX(ADDR.STATE_ID) AS STATE_ID
,MAX(ADDR.COUNTRY_ID) AS COUNTRY_ID
FROM ES_W_USER_CONT_INF USC
LEFT JOIN DW_ERSDB_LDSJOBS_ADDRESS ADDR ON (USC.ADDRESS_ID =
ADDR.ADDRESS_ID)
GROUP BY USC.USER_ID
我最好的尝试。我意识到这很遥远,但我在编写案例陈述方面没有太多经验:
SELECT USC.USER_ID
,CASE
WHEN ADDR.STREET_1 IS NOT NULL THEN ADDR.STREET_1 || CHAR (10)
WHEN ADDR.STREET_1 IS NULL THEN ''
WHEN ADDR.STREET_2 IS NOT NULL THEN ADDR.STREET_2 || CHAR (10)
WHEN ADDR.STREET_2 IS NULL THEN ''
WHEN ADDR.STREET_3 IS NOT NULL THEN ADDR.STREET_3 || CHAR (10)
WHEN ADDR.STREET_3 IS NULL THEN ''
WHEN ADDR.STREET_4 IS NOT NULL THEN ADDR.STREET_4 || CHAR (10)
WHEN ADDR.STREET_4 IS NULL THEN ''
END
,MAX(ADDR.CITY) AS CITY
,MAX(ADDR.POSTAL_CODE) AS POSTAL_CODE
,MAX(ADDR.STATE_ID) AS STATE_ID
,MAX(ADDR.COUNTRY_ID) AS COUNTRY_ID
FROM DSS_ERS_STAGE.ES_W_USER_CONT_INF USC
LEFT JOIN DSS_ERS_STAGE.ES_W_ADDRESS ADDR ON (USC.ADDRESS_ID =
ADDR.ADDRESS_ID)
GROUP BY USC.USER_ID