标签:type sum res index and htm else user cts
批次导数据表头
SELECT [运单号] ,
[运单号] AS [订单号] ,
[运单号] AS [订单号] ,
[运单号] ,
SUM([price] * [ProductNum]) AS [订单总价] ,
SUM(CAST(( temp.[Weight] * ( CAST (temp.ProductNum AS DECIMAL(18, 2))
/ temp.ProductSumNum ) ) AS NUMERIC(18, 2))) AS [毛重] ,
SUM(CAST(( temp.[Weight] * ( CAST (temp.ProductNum AS DECIMAL(18, 2))
/ temp.ProductSumNum ) ) AS NUMERIC(18, 2))
- 0.01) AS [净重] ,
temp2.TrueName AS [收货人] ,
temp2.Adrress AS [收货人地址] ,
CASE temp2.Mobile
WHEN ‘‘ THEN temp2.Phone
ELSE temp2.Mobile
END AS [电话] ,
temp.币制 ,
‘‘ AS [orderType] ,
‘‘ AS [trafMode] ,
‘‘ AS [portCode] ,
‘‘ AS [licenseNo] ,
‘‘ AS [wrapType] ,
‘‘ AS [freight] ,
‘‘ AS [insuredFee] ,
‘‘ AS [freightMark] ,
‘‘ AS [insuredFeeMark] ,
‘‘ AS [goodsInfo] ,
‘‘ AS [consigneeCountry] ,
‘‘ AS [shipper] ,
‘‘ AS [shipperAddress] ,
‘‘ AS [shipperTelephone] ,
‘‘ AS [shipperCountry] ,
‘‘ AS [orderNote] ,
‘‘ AS [logisticsNote] ,
‘‘ AS [InventoryNote] ,
‘‘ AS [trafName] ,
‘‘ AS [voyageNo] ,
‘‘ AS [billNo] ,
‘1‘ AS packNo
FROM ( SELECT a.TransportOrderCode AS [运单号] ,
MAX(ISNULL(d.CatalogName,
SUBSTRING(ProductCatalogName,
CHARINDEX(‘-‘, ProductCatalogName)
+ 1, LEN(ProductCatalogName)))) CatalogName ,
d.itemName ,
d.itemNo ,
d.gcode AS Hscode ,
CASE WHEN a.Weight < 0.02 THEN 0.02
ELSE a.Weight
END AS [Weight] ,
SUM(c.ProductNum) AS ProductNum ,
CAST(CAST(SUM(c.TotalItemActualPrice) * 0.1498 AS DECIMAL(11,
2))
/ SUM(c.ProductNum) AS DECIMAL(11, 2)) [price] ,
‘美元‘ AS [币制] ,
dbo.Fun_GetTransportProductNum(a.TransportOrderID) AS ProductSumNum ,
d.unit ,
d.unit1
FROM dbo.TWX_TransportOrder a WITH ( NOLOCK )
LEFT JOIN dbo.TWX_TransportFromMst b WITH ( NOLOCK ) ON a.TransportOrderID = b.TransportOrderID
LEFT JOIN dbo.TWX_TransportFromDtl c WITH ( NOLOCK ) ON b.TransportFormMstID = c.TransportFormMstID
LEFT JOIN dbo.TBD_ProductCatalog_MAP_KJT d WITH ( NOLOCK ) ON c.ProductCatalogID = d.CatalogID
AND c.DeleteUser = 0
WHERE a.StatusFlag >= 20
AND a.LogisticsTransferDtlID IN (
SELECT LogisticsTransferDtlID
FROM dbo.TWX_LogisticsTransferDtl WITH ( NOLOCK )
WHERE LogisticsTransferDtlCode IN (
SELECT [LogisticsTransferDtlCode]
FROM TWX_ScanLogisticsTransfer WITH ( NOLOCK )
WHERE DeleteUser = 0
AND BatchNo = ‘113020170828‘ ) )
GROUP BY a.TransportOrderCode ,
itemName ,
itemNo ,
d.gcode ,
a.Weight ,
d.unit ,
a.TransportOrderID ,
d.unit1
) temp
LEFT JOIN dbo.TWX_TransportOrder temp2 ON temp.[运单号] = temp2.TransportOrderCode
GROUP BY temp.[运单号] ,
temp.[币制] ,
temp2.TrueName ,
temp2.Adrress ,
temp2.Mobile ,
temp2.Phone;
-------------------------------------------------------------------.
(SELECT TOP 1 C.CreateTime FROM TWX_LogisticsTransferDtl A
LEFT JOIN TWX_ScanLogisticsTransfer C ON A.LogisticsTransferDtlCode=C.LogisticsTransferDtlCode
WHERE A.LogisticsTransferDtlID=a.LogisticsTransferDtlID
) AS ‘装车时间‘,
(
SELECT TOP 1 N.TrackTime FROM
[dbo].[Log_TransportOrderTrack] N WHERE N.TransportOrderCode=a.TransportOrderCode AND N.TrackCode IN (‘CAI_CUSTOMS_CLR_SUC_00‘,‘CAI_CUSTOMS_CLR_SUC_HK‘)
) AS ‘到港时间‘,
(
SELECT TOP 1 N.TrackTime FROM
[dbo].[Log_TransportOrderTrack] N WHERE N.TransportOrderCode=a.TransportOrderCode AND N.TrackCode=‘CAI_SIGN_IN‘
)
AS ‘签收时间‘
标签:type sum res index and htm else user cts
原文地址:https://www.cnblogs.com/chengjun/p/9003655.html