December 13, 2008 at 4:25 pm
I have the following vertical table that I need to be able to PIVOT for easier reading
PROJECT PROJECT NAME DATE Category Milestone Date
100001 3PO Feasibility Due 9/10/2007
100001 3PO Executive Presentation 9/30/2007
100001 3PO Requirements Due 1/10/2008
100001 3PO Staff Confirmed 1/15/2008 100001 HCE Feasibility Due 9/10/2007
100001 HCE Executive Presentation 9/30/2007
100001 HCE Requirements Due 1/10/2008
100001 HCE Staff Confirmed 1/15/2008
The table is actually a view that pulls data from the PROJECT and PROJECT DATES tables. Its a one-to-many relationship. Given that the Milestone Date needs to be presented as is - I need to know how to create the pivot without using an aggregate.
December 13, 2008 at 7:42 pm
Please post what you'd like the output to look like and, if you provide the data in a readily consumable format like that outline in the link in my signature below, I betting someone which actually try to help you. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
December 14, 2008 at 9:41 am
My bad. Let's just pretend that that post was never posted as I now realize that it was way screwed up.
The Vertical table is
100001 3PO Feasibility Due 9/10/2007
100001 3PO Executive Presentation 9/30/2007
100001 3PO Requirements Due 1/10/2008
100001 3PO Staff Confirmed 1/15/2008
100002 HCE Feasibility Due 9/10/2007
100002 HCE Executive Presentation 9/30/2007
100002 HCE Requirements Due 1/10/2008
100002 HCE Staff Confirmed 1/15/2008
The output should be
Project Name Feasibility Exe Presentation Requriements Staff
100001 3PO 9/10 9/30 1/10 1/15
100002 HCE 9/10 9/30 1/10 1/15
December 14, 2008 at 8:45 pm
It's pretty obvious that you didn't read the article I directed you to. Your problem is simple and so are the methods I directed you to. Post your data in the format I asked for in the article to make my life simple and I'll return the favor in spades.;)
--Jeff Moden
Change is inevitable... Change for the better is not.
December 14, 2008 at 9:54 pm
If I could write the T-SQL then I'd post it. I am presented the data as it exists in the tables and as I need it displayed. Either help or don't bother.
December 15, 2008 at 4:42 am
Heh... you can't take the time to make a dozen insert statements and a create table statement to help me help you... good luck.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 15, 2008 at 4:56 am
david.c.holley (12/14/2008)
If I could write the T-SQL then I'd post it. I am presented the data as it exists in the tables and as I need it displayed. Either help or don't bother.
If you don't want to put time into making it easier for us to help you, how could you ever expect from us that we will put time into helping you? This won't make you very popular you know.
Look for Jeff Moden's articles about Pivot data. Case closed, help yourself.
Ronald HensbergenHelp us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/-------------------------------------------------------------------------2+2=5 for significant large values of 2
December 15, 2008 at 6:54 pm
david.c.holley (12/14/2008)
If I could write the T-SQL then I'd post it. I am presented the data as it exists in the tables and as I need it displayed. Either help or don't bother.
Not bothering
December 15, 2008 at 7:00 pm
david.c.holley (12/14/2008)
If I could write the T-SQL then I'd post it. I am presented the data as it exists in the tables and as I need it displayed. Either help or don't bother.
You do know that those of us who provide help on these forums do so on our own time and for free. If you want our help, you need to help us out by giving us the things we need to help you. You'll find all that in the article that Jeff wrote, and I have referenced below as well in my signature block.
We don't ask for this to be mean, but our time is just as valuable as yours, and anything you can do to make helping you easier is extremely welcome.
December 15, 2008 at 8:09 pm
Although I thought I'd not bother with this either, I decided to at least provide you with one solution.
I have also taken the time to create the scripts that you were asked to create and provide. Use this as a template for future requests for help. You will find that those you blew of with "either help or don't bother" will be more willing to help.
create table dbo.Project (
ProjectID int,
ProjectName char(3),
ProjectMileStone varchar(50),
MileStoneDueDate datetime
);
insert into dbo.Project(
ProjectID,
ProjectName,
ProjectMileStone,
MileStoneDueDate)
select 10001,'3PO','Feasibility Due','2007-09-10' union all
select 10001,'3PO','Executive Presentation','2007-09-30' union all
select 10001,'3PO','Requirements Due','2008-01-10' union all
select 10001,'3PO','Staff Confirmed','2008-01-15' union all
select 10002,'HCE','Feasibility Due','2007-09-10' union all
select 10002,'HCE','Executive Presentation','2007-09-30' union all
select 10002,'HCE','Requirements Due','2008-01-10' union all
select 10002,'HCE','Staff Confirmed','2008-01-15';
select * from dbo.Project;
with MyPivot (
ProjectID,
ProjectName,
FeasibilityDue,
ExecutivePresentation,
RequirementsDue,
StaffConfirmed
) as (
select
ProjectID,
ProjectName,
max(case when ProjectMileStone = 'Feasibility Due' then MileStoneDueDate else null end),
max(case when ProjectMileStone = 'Executive Presentation' then MileStoneDueDate else null end),
max(case when ProjectMileStone = 'Requirements Due' then MileStoneDueDate else null end),
max(case when ProjectMileStone = 'Staff Confirmed' then MileStoneDueDate else null end)
from
dbo.Project
group by
ProjectID,
ProjectName
)
select
*
from
MyPivot;
drop table dbo.Project;
December 15, 2008 at 8:18 pm
David:
Are you saying that you do not know how to generate the CREATE TABLE script or the data INSERT's as described in the article?
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
December 16, 2008 at 2:26 am
Lynn Pettis (12/15/2008)
Although I thought I'd not bother with this either, I decided to at least provide you with one solution.I have also taken the time to create the scripts that you were asked to create and provide. Use this as a template for future requests for help. You will find that those you blew of with "either help or don't bother" will be more willing to help.
Lynn, you're too nice!
Ronald HensbergenHelp us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/-------------------------------------------------------------------------2+2=5 for significant large values of 2
December 16, 2008 at 2:35 pm
r.hensbergen (12/16/2008)
Lynn, you're too nice!
I agree! WAY too nice.
December 16, 2008 at 8:20 pm
Been busy...
For the record, the discussion groups that I have been apart of do not have stringent rules as to what needs to be included and what does not. Within that framework, the information that I provided would have been sufficient.
I'll be looking for a forum a bit more consistent with my prior experience so as not to waste your time. Thank you though for the code that was posted.
December 16, 2008 at 8:36 pm
As Kappa Mikey would say: "W'ver."
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 15 posts - 1 through 15 (of 22 total)
You must be logged in to reply to this topic. Login to reply