我想从我在查询中选择的表中获取所有字段,即使字段不包含值(值 null 或空)。以下是我写的查询。
SELECT (
SELECT T1.[CarrierCode_Destination] AS '@CarrierCode_Destination',
T1.[CarrierCode_Destination_Address] AS
'@CarrierCode_Destination_Address',
T1.[CarrierCode_Destination_Address1] AS
'@CarrierCode_Destination_Address1',
T1.[CarrierCode_Destination_Address2] AS
'@CarrierCode_Destination_Address2',
T1.[CIMtrek_RegContact] AS '@CIMtrek_RegContact',
T1.[CIMtrek_CarrierContact] AS '@CIMtrek_CarrierContact',
[T1].[CIMtrek_AdditionalContacts] AS
'@CIMtrek_AdditionalContacts'
FROM (
SELECT CD.[CIMtrek_DestinationName]
CarrierCode_Destination,
CD.[CIMtrek_DestinationAdd]
CarrierCode_Destination_Address,
CD.[CIMtrek_DestinationAdd_1]
CarrierCode_Destination_Address1,
CD.[CIMtrek_DestinationAdd_2]
CarrierCode_Destination_Address2,
CD.[CIMtrek_RegContact] CIMtrek_RegContact,
CD.[CIMtrek_CarrierContact] CIMtrek_CarrierContact,
CD.[CIMtrek_AdditionalContacts]
CIMtrek_AdditionalContacts
FROM CIMtrek_SystemTable_DatawareHouse CD
WHERE LEN(
LTRIM(
RTRIM(ISNULL(LTRIM(RTRIM(CD.[CIMtrek_DestinationName])), ''))
)
) != 0
) AS T1
FOR XML PATH('Record'),
TYPE
) FOR XML PATH('CarrierCode_Destination'),
TYPE
我得到的结果是
<CarrierCode_Destination>
<Record CarrierCode_Destination="8S - San Fran" CarrierCode_Destination_Address="SAN FRANCISCO - Redistribution" CarrierCode_Destination_Address1="4025 Whipple Road, " CarrierCode_Destination_Address2="Union City CA 94587" CIMtrek_RegContact="RDC San Francisco" />
<Record CarrierCode_Destination="8G - St Louis" CarrierCode_Destination_Address="ST. LOUIS - Redistribution" CarrierCode_Destination_Address1="126 Enterprise Drive, " CarrierCode_Destination_Address2="Wentzville MO 63385" CIMtrek_RegContact="RDC St Louis" />
<Record CarrierCode_Destination="V8 PHO/CYPR/CUST/TL " />
</CarrierCode_Destination>
但我想要查询中选择的所有字段。如果您看到结果,它会为我提供有价值的字段并省略没有值的字段。
如何做到这一点,请帮助。
最好的祝福