我有这个查询:
USE [VERPLOEGEN-NAV2009-LIVE]
SELECT *
--V.[Location Code] --as LeveranciersName
FROM
(SELECT
V.Name as LeveranciersName, V.No_,SU.[Reorder Cycle] as frequentie
,SU.[Location Code] as location, V.[Freight-free Limit] AS Vrachtvrije_Limiet ,
SUM(VLE.[Purchase (LCY)]) as Inkoopomzet
--CAST(REPLACE(REPLACE((VLE.[Purchase (LCY)]), '(', '-'), ')','') AS MONEY)AS Inkoopomzet
FROM
[Verploegen POC$Vendor] V
JOIN [Verploegen POC$Vendor Ledger Entry] VLE ON VLE.[Vendor No_] = V.No_
AND VLE.[Posting Date] BETWEEN '2016-01-01' AND '2016-12-31'
JOIN
[Verploegen POC$Stockkeeping Unit] SU ON V.No_ = SU.[Vendor No_]
AND SU.[Reordering Policy] = 2
JOIN [Verploegen POC$Item] I ON I.No_ = SU.[Item No_]
GROUP BY V.Name, V.No_, SU.[Location Code], su.[Reorder Cycle], V.[Freight-free Limit],VLE.[Purchase (LCY)]
) AS V
PIVOT
(
SUM(V.Inkoopomzet)
--SUM([Purchase (LCY)])
--FOR Location Code IN ([DB], [DL], [AM], [RD], [ZM])
--FOR [Verploegen POC$Activity]
FOR location in ([AM], [DB],[DL], [RD], [ZM])
)AS ptt
ORDER BY LeveranciersName
--[Verploegen POC$Vendor] V
但需要25秒。
您可以给我什么建议,以便查询的执行时间缩短时间
谢谢
等问题。此查询的输出是:
ADW Groothandel bv 3306 300.00000000000000000000 -165404.24000000000000000000 -165404.24000000000000000000 -165404.24000000000000000000 -165404.24000000000000000000 -165404.24000000000000000000
但我想解析数字:165404.24谢谢
我试着这样投:
USE [VERPLOEGEN-NAV2009-LIVE]
SELECT *
--V.[Location Code] --as LeveranciersName
FROM
(SELECT
V.Name as LeveranciersName, V.No_,SU.[Reorder Cycle] as frequentie
,SU.[Location Code] as location, V.[Freight-free Limit] AS Vrachtvrije_Limiet ,
SUM(VLE.[Purchase (LCY)]) as Inkoopomzet
--SUM(CAST(VLE.[Purchase (LCY)] as money),1) as Inkoopomzet)
--CAST(REPLACE(REPLACE((VLE.[Purchase (LCY)]), '(', '-'), ')','') AS MONEY)AS Inkoopomzet
FROM
[Verploegen POC$Vendor] V
JOIN [Verploegen POC$Vendor Ledger Entry] VLE ON VLE.[Vendor No_] = V.No_
AND VLE.[Posting Date] BETWEEN '2016-01-01' AND '2016-12-31'
JOIN
[Verploegen POC$Stockkeeping Unit] SU ON V.No_ = SU.[Vendor No_]
AND SU.[Reordering Policy] = 2
JOIN [Verploegen POC$Item] I ON I.No_ = SU.[Item No_]
GROUP BY V.Name, V.No_, SU.[Location Code], su.[Reorder Cycle], V.[Freight-free Limit],VLE.[Purchase (LCY)]
) AS V
PIVOT
(
--SUM(V.Inkoopomzet)
SUM(CAST(VLE.[Purchase (LCY)] as money),1) as Inkoopomzet)
--SUM([Purchase (LCY)])
--FOR Location Code IN ([DB], [DL], [AM], [RD], [ZM])
--FOR [Verploegen POC$Activity]
FOR location in ([AM], [DB],[DL], [RD], [ZM])
)AS ptt
ORDER BY LeveranciersName
--[Verploegen POC$Vendor] V
但它给出了错误