Traspossing rows to columns

domenica 14 ottobre 2007 - 10.17

aleplgr Profilo | Junior Member

Hi, excuses for writing in english, but maybe someone can help me. I've got a table of a test applied to patients in different dates:

PATID DATE ITEMa ITEMb ITEMc ITEMd

PATIENTID is the identification of the patient
DATE is the date the test took place, one patient may have many (up to 7) different dates
ITEMa...ITEMf are the points the patient took in the questions of the test.
So now there are many rows for each patient, one row for each date the test is applied.

I need to generate one table where each patient appears in only one row, and the DATE and ITEMs are new columns for each different DATE. For example if all the patients appear at most in 2 different dates, the resulting table should be like this:

PATID DATE1 ITEMa1 ITEMb1 ITEMc1 ITEMd1 DATE2 ITEMa2 ITEMb2 ITEMc2 ITEMd2

If all the patients had at most 3 different dates, at the right of ITEMd2 should appear
DATE3 ITEMa3 ITEMb3 ITEMc3 ITEMd3
and so on up to 7



lbenaglia Profilo | Guru

>I need to generate one table where each patient appears in only
>one row, and the DATE and ITEMs are new columns for each different
>DATE.

Hi alex,

what DBMS are you using?

Ciao!
--
Lorenzo Benaglia
Microsoft MVP - SQL Server
http://blogs.dotnethell.it/lorenzo/
http://italy.mvps.org

aleplgr Profilo | Junior Member

I'm using Borland InterBase 7.5 but I think (hope) this can be solved using an SQL query independently of the dbms, or if not independent at least with the standard sql...
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5