• Hi Guys

    Thx for the responses. I have the following data

    SUB_DISTRICT ... LOCATION_TYPE ... Date

    Paris Inland 2012/1/1

    Nigeria Inland 2012/1/2

    Brasil Coast 2012/6/3

    Paris Inland 2012/2/2

    Nigeria Inland 2012/5/5

    Brasil Coast 2012/6/3

    Texas Inland 2012/12/12

    Paris Inland 2012/11/11

    Nigeria Mountain 2012/8/8

    Nigeria Mountain 2012/10/10

    Texas Inland 2012/10/12

    Texas Inland 2012/9/12

    Texas Inland 2012/1/1

    the ultimate result should be

    SUB_DISTRICT LOCATION_TYPE Q1 Q2 Q3 Q4

    Paris Inland 2 0 0 1

    Nigeria Inland 1 1 0 0

    Nigeria Mountain 0 0 0 2

    Brasil Coast 0 0 1 0

    Texas Inland 1 0 0 3

    I have tried creating the T-SQL but to no avail. Can you guide me in the right direction pls

    IF OBJECT_ID('TempDB..#Results') IS NOT NULL

    DROP TABLE #Results

    CREATE TABLE #Results (District VARCHAR(50), Location varchar(50), [Q1] INT,[Q2] INT, [Q3] INT,[Q4] INT)

    insert into #Results

    select District, Location,[Q1],[Q2],[Q3],[Q4] from

    (

    SELECT SUB_DISTRICT, LOCATION_TYPE, Q = DATEPART(QUARTER, REGISTERED_DATE)

    FROM Tata.dbo.Tbl_results_tabdel

    WHERE (TB_RESULT_TYPE IN (N'DIRECT', N'DIRECTP', N'CULAUR'))

    ) SRC

    Pivot (count(Q)

    for Q in ([Q1],[Q2],[Q3],[Q4])

    ) as PVT

    SELECT * FROM #Results