I am really new here. Currently working on SQL Server 2012.
I have table A of the following structure (records are a subset of the full data table):
CREATE TABLE [dbo].[TABLE_A](
[ASSET ID] [float] NULL,
[TASK ID] [float] NULL,
[IN_YEAR ] [float] NULL,
[IN_WEEK] [float] NULL,
[FLAG] [nvarchar](1) NULL
) ON [PRIMARY]
INSERT INTO TABLE_A
([ASSET ID], [TASK ID], [IN_YEAR], [IN_WEEK], [FLAG])
VALUES
(1, 1, 2015, 19, 'N'),
(1, 1, 2015, 20, 'Y'),
(1, 1, 2015, 21, 'N'),
(1, 2, 2015, 19, 'Y'),
(1, 2, 2015, 20, 'N'),
(1, 2, 2015, 21, 'N'),
(2, 1, 2015, 19, 'N'),
(2, 1, 2015, 20, 'N'),
(2, 1, 2015, 21, 'N')
;
In table A, we always have the same number of weeks/year for each unique combination of asset ID and task ID.
And would like to translate it into table B structure:
+----------+---------+--------------+--------------+--------------+
| Asset ID | Task ID | 2015–WEEK 19 | 2015–WEEK 20 | 2015–WEEK 21 |
+----------+---------+--------------+--------------+--------------+
| 1 | 1 | N | Y | N |
| 1 | 2 | Y | N | N |
| 2 | 1 | N | N | N |
+----------+---------+--------------+--------------+--------------+
Any thoughts?