2017-08-31 57 views
1

所以我有這樣的:如何在動態數據透視中舍入數字?

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 

它返回我:

enter image description here

如何刪除小數位中選擇本身。我無法編輯表格中的列並減少小數位數。因此,我需要編輯此查詢以返回不帶小數的值。

謝謝!

回答

1

應該只是將SUM(Amount)更改爲cast(SUM(Amount) as int)或者floor(SUM(Amount)),它會起作用。