|
Nir_parekh
Starting Member
3 Posts |
Posted - 2008-08-01 : 10:50:07
|
| Hi,I have this table. #######################################################################################GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[Tracking]([Tracking_ID] [int] IDENTITY(1,1) NOT NULL,[Respondent_ID] [int] NOT NULL,[Survey_ID] [int] NOT NULL,[Question_ID] [int] NOT NULL,[Time_Stamp] [datetime] NOT NULL CONSTRAINT [DF_Tracking_Time_Stamp] DEFAULT (getdate()),[strURL] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,[blnSuccess] [bit] NULL CONSTRAINT [DF_Tracking_blnSuccess] DEFAULT (0),[strParentURL] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[Seq] [int] NULL CONSTRAINT [DF_Tracking_Seq] DEFAULT (0),[strTitle] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,CONSTRAINT [PK_Tracking] PRIMARY KEY CLUSTERED ([Tracking_ID] 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 OFFGO####################################################################################### There are my datas in table. #######################################################################################INSERT INTO TABLE1 VALUES(296361,1154,6,'2005-09-06 12:11:42.903','http://www.jnj.com/home.htm',0,NULL,0,'Johnson & Johnson') INSERT INTO TABLE1 VALUES(296361,1154,6,'2005-09-06 12:12:03.823','http://www.jnj.com/home.htm',0,NULL,0,'Johnson & Johnson')INSERT INTO TABLE1 VALUES(296361,1154,6,'2005-09-06 12:11:42.340','http://www.jnj.com/student_resources/index.htm;jsessionid=TJQTNMSOU531QCQPCCFSZOYKB2IIQNSC',0,NULL,0,'Johnson & Johnson')INSERT INTO TABLE1 VALUES(296361,1154,6,'2005-09-07 17:08:58.933','http://www.jnj.com/home.htm',0,NULL,0,'Johnson & Johnson')INSERT INTO TABLE1 VALUES(296363,1154,6,'2005-09-06 12:14:26.793','http://www.jnj.com/home.htm',0,NULL,0,'Johnson & Johnson')INSERT INTO TABLE1 VALUES(309205,1154,6,'2005-09-20 08:22:15.570','http://www.jnj.com/home.htm',0,NULL,0,'Johnson & Johnson')INSERT INTO TABLE1 VALUES(311547,1154,6,'2005-09-22 14:33:39.640','http://www.jnj.com/home.htm',0,NULL,0,'Johnson & Johnson')INSERT INTO TABLE1 VALUES(311547,1154,6,'2005-09-22 14:36:11.000','http://www.jnj.com/home.htm',0,NULL,0,'Johnson & Johnson')####################################################################################### Now I want to generate an output like this. 1. it should be grouped by "responsent_id, question_id"2. strURL needs to be shown as Columns for each "responsent_id, question_id"3. for example, if there are 6 records for a particular "responsent_id, question_id", it should show as a single row only, containing responsent_id, question_id, and six columns to be shown as strURL. Same for each "responsent_id, question_id", whatever number of records found for it, it should show all strURL for that as columns and should represent only a single row. I tried using Pivot by finding some examples from google but somehow couldnt complete it as was facing different problems with each example. Can you please tell me how to achieve this? Thanks,Nirav |
|