Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Older Versions of SQL (v6.5, v6.0, v4.2)
»
Older Versions of SQL (v6.5, v6.0, v4.2)
»
Taking rows RegID Date (Registration with...
Taking rows RegID Date (Registration with multiple dates) and changing format to columns)
Rate Topic
Display Mode
Topic Options
Author
Message
Debbie Edwards
Debbie Edwards
Posted Wednesday, February 18, 2009 9:46 AM
SSC-Addicted
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 4:50 AM
Points: 423,
Visits: 633
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.
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
Post #659571
Jan Van der Eecken
Jan Van der Eecken
Posted Tuesday, March 17, 2009 4:05 PM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 7:12 AM
Points: 2,269,
Visits: 5,960
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
. 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
--------------------------------------------------------------------------
The function of good software is to make the complex appear to be simple. (Grady Booch)
Post #677964
Debbie Edwards
Debbie Edwards
Posted Wednesday, March 18, 2009 3:14 AM
SSC-Addicted
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 4:50 AM
Points: 423,
Visits: 633
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
Post #678205
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.