Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Taking rows RegID Date (Registration with multiple dates) and changing format to columns)


Taking rows RegID Date (Registration with multiple dates) and changing format to columns)

Author
Message
Debbie Edwards
Debbie Edwards
SSC-Addicted
SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)

Group: General Forum Members
Points: 466 Visits: 696
Hi
I have tried and failed many times now to try and get my head round this problem but its cropped up again and I could really do with some help.
Blink
I have a registration (2 in the example) and they each have a number of conferences against them.

The example data is as follows

/****** Object: Table [dbo].[ECAFALL] Script Date: 18/02/2009 11:10:05 ******/
CREATE TABLE [dbo].[Registration_Conference_Dates](
[Registration_ID] [int] NULL,
[Conference_Actual_Date] [datetime] NULL,
[Number of Conferences on date] [Int]
) ON [PRIMARY]

INSERT INTO [dbo].[ECAFALL]
(Person, Type, [ID], START_DATE, END_DATE)
SELECT 12054, 'ECAFSTD', 496815, '2007-08-29 13:37:35.923', '2007-08-29 13:38:15.357'
UNION

SELECT 17039,'2008-07-15 00:00:00.000',3
UNION
SELECT 17039,'2008-12-04 00:00:00.000',2
UNION
SELECT 17039,'2009-02-13 00:00:00.000',3
UNION
SELECT 18867,'2005-12-21 00:00:00.000',2
UNION
SELECT 18867,'2006-03-07 00:00:00.000',2
UNION
SELECT 18867,'2006-07-11 00:00:00.000',7
UNION
SELECT 18867,'2006-12-13 00:00:00.000',5

How do I get the above into this format.......

Registration_ID Date1 Date2 Date3 Date4
17039 '2008-07-15 00:00:00.000' '2008-12-04 00:00:00.000' '2009-02-13 00:00:00.000'
18867 '2005-12-21 00:00:00.000' '2006-03-07 00:00:00.000' '2006-07-11 00:00:00.000' '2006-12-13 00:00:00.000'


The Registrations can have up to 30 dates attatched. This is intended to create just one row of data for each registration showing the entire life of the process
Jan Van der Eecken
Jan Van der Eecken
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2212 Visits: 6490
Hi Debbie,

You CAN do this in T-SQL if you REALLY want to, but it would probably involve using cursors, yuk, so we won't want to go there, and in fact I don't even want to think how to do it. Jeff would hate me for giving you such a solution in the first place :-D. Anyhow, this is not something you want to do on the server, it should be done in your front-end. Just get the data out in the right order, then assign it to the Date1, Date2 etc. column in the output grid or wherever you want to present the data.

And by the way, your CREATE TABLE statement doesn't match the table your sample data refers to. But that's an aside.

Greets,
Jan

--------------------------------------------------------------------------
A little knowledge is a dangerous thing (Alexander Pope)

In order for us to help you as efficiently as possible, please read this before posting (courtesy of Jeff Moden)
Debbie Edwards
Debbie Edwards
SSC-Addicted
SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)

Group: General Forum Members
Points: 466 Visits: 696
Whoops sorry about that.

I used an old create table script and didnt finish it properly.

Thanks for the advice. I think I used MIN, MAX and then grabbed the other ID that isnt in the min OR MAX temporaty tables.

Debbie
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search