Click here to Skip to main content
15,799,398 members
Home / Discussions / Database
   

Database

 
QuestionTranspose multiple rows into multiple columns in SQL Server Pin
Davidemazzuuu13-May-14 5:52
Davidemazzuuu13-May-14 5:52 
AnswerRe: Transpose multiple rows into multiple columns in SQL Server Pin
Corporal Agarn13-May-14 6:46
professionalCorporal Agarn13-May-14 6:46 
GeneralRe: Transpose multiple rows into multiple columns in SQL Server Pin
Davidemazzuuu13-May-14 22:11
Davidemazzuuu13-May-14 22:11 
AnswerRe: Transpose multiple rows into multiple columns in SQL Server Pin
Mycroft Holmes13-May-14 13:53
professionalMycroft Holmes13-May-14 13:53 
GeneralRe: Transpose multiple rows into multiple columns in SQL Server Pin
Davidemazzuuu13-May-14 22:04
Davidemazzuuu13-May-14 22:04 
GeneralRe: Transpose multiple rows into multiple columns in SQL Server Pin
Mycroft Holmes13-May-14 22:30
professionalMycroft Holmes13-May-14 22:30 
GeneralRe: Transpose multiple rows into multiple columns in SQL Server Pin
Davidemazzuuu13-May-14 23:27
Davidemazzuuu13-May-14 23:27 
GeneralRe: Transpose multiple rows into multiple columns in SQL Server Pin
Member 1026233013-May-14 22:34
Member 1026233013-May-14 22:34 
hi,
use this table as example:

SQL
COD    surname   name    CODCAU   from         from_time   to           to_time   period
1      ROSSI     MARCO   301      19/09/2005   0.00        23/09/2005   0.00      p1
1      ROSSI     MARCO   301      09/12/2005   0.00        09/12/2005   0.00      p2
1      BIANCHI   FABIO   301      12/01/2004   0.00        16/01/2004   0.00      p1
1      BIANCHI   FABIO   301      02/04/2004   0.00        02/04/2004   0.00      p2
1      BIANCHI   FABIO   301      02/05/2004   0.00        10/05/2004   0.00      p3


then to pivot:

SQL
select *
FROM
(
   --concatenate to create a period on unique column...
   SELECT surname,name,COD,from+' '+from_time+' '+to+' '+to_time as date,period
   FROM [pivot]
) as s
PIVOT
(
   --pivot aggregate by the columns different by 'date/period' -> (surname,name,COD)
   max(date)
   FOR period IN ([p1],[p2],[p3])
)AS p

QuestionSQL Server 2012 Cube Build failing. Pin
rnbergren12-May-14 10:52
rnbergren12-May-14 10:52 
QuestionAccess DB Pin
Zeyad Jalil11-May-14 20:45
professionalZeyad Jalil11-May-14 20:45 
AnswerRe: Access DB Pin
Bernhard Hiller11-May-14 23:30
Bernhard Hiller11-May-14 23:30 
AnswerRe: Access DB Pin
sankarsan parida12-May-14 20:33
professionalsankarsan parida12-May-14 20:33 
Questionhow to return primary key when insert statement violates unique constraint Pin
Nico Haegens10-May-14 8:21
professionalNico Haegens10-May-14 8:21 
AnswerRe: how to return primary key when insert statement violates unique constraint Pin
PIEBALDconsult10-May-14 8:44
professionalPIEBALDconsult10-May-14 8:44 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
Nico Haegens10-May-14 9:05
professionalNico Haegens10-May-14 9:05 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
PIEBALDconsult10-May-14 11:22
professionalPIEBALDconsult10-May-14 11:22 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
Nico Haegens11-May-14 0:07
professionalNico Haegens11-May-14 0:07 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
PIEBALDconsult11-May-14 6:56
professionalPIEBALDconsult11-May-14 6:56 
AnswerRe: how to return primary key when insert statement violates unique constraint Pin
jschell11-May-14 9:17
jschell11-May-14 9:17 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
Nico Haegens12-May-14 4:20
professionalNico Haegens12-May-14 4:20 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
Richard.Berry10012-May-14 8:55
Richard.Berry10012-May-14 8:55 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
Eddy Vluggen12-May-14 9:49
professionalEddy Vluggen12-May-14 9:49 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
Corporal Agarn12-May-14 10:45
professionalCorporal Agarn12-May-14 10:45 
GeneralRe: how to return primary key when insert statement violates unique constraint Pin
jschell12-May-14 11:31
jschell12-May-14 11:31 
AnswerRe: how to return primary key when insert statement violates unique constraint Pin
Mycroft Holmes12-May-14 23:25
professionalMycroft Holmes12-May-14 23:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.