所以我有这个:
DECLARE @DynamicPivotQuery AS NVARCHAR(MAX)
DECLARE @ColumnName AS NVARCHAR(MAX)
--Get distinct values of the PIVOT Column
SELECT @ColumnName= ISNULL(@ColumnName + ',','')
+ QUOTENAME(period)
FROM (SELECT DISTINCT period FROM atbv_Accounting_Transactions WHERE lAccountNO LIKE '6%' AND Period LIKE '2017%') AS Periods
SET @DynamicPivotQuery =
N'SELECT lAccountNo, ' + @ColumnName + '
FROM (SELECT
lAccountNo, period, SUM(Amount) As Total
FROM atbv_Accounting_Transactions
WHERE lAccountNO LIKE ''6%'' AND Period LIKE ''2017%''
GROUP BY lAccountNo, period
) AS T
PIVOT(SUM(TOTAL)
FOR period IN (' + @ColumnName + ')) AS PVTTable'
--Execute the Dynamic Pivot Query
EXEC sp_executesql @DynamicPivotQuery
它让我回答:
如何删除select本身中的小数位数。我无法编辑表中的列并减少小数位。所以我需要编辑此查询以返回不带小数的值。
谢谢!
答案 0 :(得分:2)
只需将SUM(Amount)
更改为cast(SUM(Amount) as int)
或floor(SUM(Amount))
,它就可以实现。