I have a table that holds information about people that have to take physical fitness tests. They take at least three of the six events. Each event is stored as a separate record in my table. All events have to be taken on the same day. A person can do this multiple times. So, today, they can get scored on three events, then tomorrow they can get scored on the same three events or another three. so a table of data can look like this.Not complete structure, but hopefully shows what I am working with (complete structure below)userId date event score1 11/24 pushups 731 11/24 situps 851 11/24 run 811 11/25 pushups 1001 11/25 situps 1001 11/25 walk 100
I need the data for this user to be made into one row. Also, a user can be listed as many as 4 times, so for example, I would need a column for pushups1, pushups2, pushups3, pushups4, if they have taken a test on 4 different occasions.I hope this is clear enough. Below is the table and data that I have setup in my database. Any help will be greatly appreciated, as I have no clue as to what I am doing here.SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[tbl_PTRecord]( [PTRecordId] [int] IDENTITY(1,1) NOT NULL, [StudentClassId] [int] NOT NULL, [PTRecordTypeId] [int] NOT NULL, [DateTaken] [smalldatetime] NOT NULL CONSTRAINT [DF_PTRecord_DateTaken] DEFAULT (getdate()), [HeightWeightId] [int] NULL, [TotalScore] [varchar](3) NOT NULL CONSTRAINT [DF_PTRecord_TotalScore] DEFAULT ((0)), CONSTRAINT [PK_PTRecord] PRIMARY KEY CLUSTERED ( [PTRecordId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGOALTER TABLE [dbo].[tbl_PTRecord] WITH CHECK ADD CONSTRAINT [FK_tbl_PTRecord_tbl_PTRecord] FOREIGN KEY([PTRecordId])REFERENCES [dbo].[tbl_PTRecord] ([PTRecordId])GOALTER TABLE [dbo].[tbl_PTRecord] CHECK CONSTRAINT [FK_tbl_PTRecord_tbl_PTRecord]SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[tbl_PTScores]( [PTScoreId] [int] IDENTITY(1,1) NOT NULL, [PTRecordId] [int] NOT NULL, [PTEventId] [int] NOT NULL, [Score] [int] NOT NULL CONSTRAINT [DF_PTScores_Score] DEFAULT ((0)), [PointsEarned] [int] NULL, [Grader] [varchar](3) NULL, [PhysicalProfile] [bit] NOT NULL CONSTRAINT [DF_tbl_PTScores_Profile] DEFAULT ((0)), CONSTRAINT [PK_PTScores] PRIMARY KEY CLUSTERED ( [PTScoreId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGOALTER TABLE [dbo].[tbl_PTScores] WITH CHECK ADD CONSTRAINT [FK_tbl_PTScores_tbl_PTRecord] FOREIGN KEY([PTRecordId])REFERENCES [dbo].[tbl_PTRecord] ([PTRecordId])GOALTER TABLE [dbo].[tbl_PTScores] CHECK CONSTRAINT [FK_tbl_PTScores_tbl_PTRecord]GO/****** Object: Table [dbo].[tbl_PTEvents] Script Date: 11/25/2009 13:18:07 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[tbl_PTEvents]( [PTEventId] [int] IDENTITY(1,1) NOT NULL, [Event] [varchar](10) NOT NULL, [EventType] [varchar](50) NOT NULL, CONSTRAINT [PK_PTEvents] PRIMARY KEY CLUSTERED ( [PTEventId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFINSERT tbl_PTEvents(PTEventId,Event,EventType) VALUES('1','Push-Ups','Repitions')INSERT tbl_PTEvents(PTEventId,Event,EventType) VALUES('2','Sit-Ups','Repitions')INSERT tbl_PTEvents(PTEventId,Event,EventType) VALUES('3','Run','Time')INSERT tbl_PTEvents(PTEventId,Event,EventType) VALUES('4','Walk','Time')INSERT tbl_PTEvents(PTEventId,Event,EventType) VALUES('5','Swim','Time')INSERT tbl_PTEvents(PTEventId,Event,EventType) VALUES('6','Bike','Time')INSERT INTO tbl_PTRecord (StudentClassId, PTRecordTypeId, DateTaken, HeightWeightId, TotalScore) VALUES (1, 1, '11/24/09', 1, 180)INSERT INTO tbl_PTRecord (StudentClassId, PTRecordTypeId, DateTaken, HeightWeightId, TotalScore) VALUES (1, 2, '11/25/09', 1, 300)INSERT INTO tbl_PTRecord (StudentClassId, PTRecordTypeId, DateTaken, HeightWeightId, TotalScore) VALUES (2, 1, '11/24/09', 1, 279)INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('415','1','1','71','94','mc','0')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('416','1','4','671','100','mc','0')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('417','1','2','71','88','mc','0')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('418','2','1','0','0','mc','1')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('419','2','4','61','100','mc','0')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('420','2','2','0','0','mc','1')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('421','3','1','78','100','mc','0')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('422','3','4','756','100','mc','0')INSERT tbl_PTScores(PTScoreId,PTRecordId,PTEventId,Score,PointsEarned,Grader,PhysicalProfile) VALUES('423','3','2','92','100','mc','0')