2017-08-31 10 views
1

だから私は、この持っている:私は自分自身の選択の中に小数点以下の桁数を削除するにはどうすればよいダイナミックピボット内で数値を丸める方法は?

enter image description here

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 

をそれは私にこれを返します。私はテーブルの列を編集し、小数点以下の桁数を減らすことはできません。私は小数点なしで値を返すようにこのクエリを編集する必要があります。

ありがとうございます!

答えて

1

ちょうどSUM(Amount)cast(SUM(Amount) as int)またはおそらくfloor(SUM(Amount))に変更する必要があり、それはトリックを行います。

関連する問題