I am using SQL Server 2012 and I am running the following T-SQL pivot query:
USE MyDatabase
SELECT PropertyCode, ISNULL([AUGUST 2015],0) AS 'August 2015' FROM
(
SELECT [PropertyCode], [MTH], [Package Revenue Excl VAT]
FROM [RSDLIST]) m
PIVOT (SUM([Package Revenue Excl VAT]) FOR [MTH] IN
([AUGUST 2015]
)) AS PVTTABLE
An extract of my output is shown below:
PropertyCode August 2015
Smith 15071923.019032
Jones 2152483.164654
Steeve 7136836.891117
I need to format the second column so that the output becomes:
PropertyCode August 2015
Smith 15,071,923
Jones 2,152,483
Steeve 7,136,836
I've had a look at the answers provided here : Format a number with commas but without decimals in SQL Server 2008 R2
and this one from Microsoft: Format (T-SQL)
I've tried the first one by replacing [Package Revenue Excl VAT] at line 3 with the following:
CONVERT(varchar,CAST(a.[Package Revenue Excl VAT] AS MONEY),1) AS 'Pkg Rev'
However, since the values have been converted into a varchar, they can't be used in the Pivot query!