Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3316

Re: How to convert Year( T0.[DocDate] ) to variable?

$
0
0

Try this

 

 

 

 

DECLARE @d1 AS NVARCHAR(200)

/* Select   T1.year from  [dbo].[OACP] t1 */

SET @d1 = /* T1.year  */ '[%1]'

 

 

SELECT [KAM] AS 'Sales Agent',

       [1] AS January,

       [2] AS February,

       [3] AS March,

       [4] AS April,

       [5] AS May,

       [6] AS June,

       [7] AS July,

       [8] AS August,

       [9] AS September,

       [10] AS October,

       [11] AS November,

       [12] AS December,

       ISNULL([1], 0) + ISNULL([2], 0) + ISNULL([3], 0) + ISNULL([4], 0) +

       ISNULL([5], 0) + ISNULL([6], 0) + ISNULL([7], 0) + ISNULL([8], 0) +

       ISNULL([9], 0) + ISNULL([10], 0) + ISNULL([11], 0) + ISNULL([12], 0) AS

       'Total'

FROM   (

           SELECT T1.[SlpName] AS KAM,

                  SUM(T0.[DocTotal] -T0.[VatSumSy]) AS Total,

                  MONTH(T0.[DocDate]) AS MONTH

           FROM   OINV T0

                  INNER JOIN OSLP T1

                       ON  T0.SlpCode = T1.SlpCode

           WHERE  T0.[CANCELED] = 'N'

                  AND T0.[DocTotal] -T0.[VatSumSy] > 0

                  AND YEAR(T0.[DocDate]) = @d1

           GROUP BY

                  T1.[SlpName],

                  T0.[DocDate]

       )S PIVOT(

           SUM(Total) FOR MONTH IN ([1], [2], [3], [4], [5], [6], [7], [8], [9],

                                   [10], [11], [12])

       ) P

ORDER BY

       [Sales Agent]

 

 

Cheers!!!


Viewing all articles
Browse latest Browse all 3316

Trending Articles