Union query help

  • Thread starter Thread starter JRW
  • Start date Start date
J

JRW

I want to combine multiple columns (from two diff tables) into one column
and have another column "describe" what the new row is. I currently have:

SELECT [Project],[Duedate] AS [MilestoneDt]
FROM [Datalock]
UNION SELECT [Project],[PA DT]
FROM [OtherProjects]
UNION SELECT [Project],[FP DT]
FROM [OtherProjects]
ORDER BY [MilestoneDt]

which produces the structure:
Project | MilestoneDt
ProjA | 6/01/1996
ProjA | 10/16/1996
ProjA | 1/1/1997
ProjB | 2/01/2004
ProjB | 3/5/2004
ProjB | 4/18/2004
etc.

however, I would like to have another column (MilestoneDescription) describe
what each "row" is"

Project | MilestoneDt | MilestoneDescription
ProjA | 6/01/1996 | DueDate
ProjA | 10/16/1996 | PA DT
ProjA | 1/1/1997 | FP DT
ProjB | 2/01/2004 | DueDate
ProjB | 3/5/2004 | PA DT
ProjB | 4/18/2004 | FP DT

Any thoughts on how to get the other column?
JRW
 
JRW said:
I want to combine multiple columns (from two diff tables) into one column
and have another column "describe" what the new row is. I currently have:

SELECT [Project],[Duedate] AS [MilestoneDt]
FROM [Datalock]
UNION SELECT [Project],[PA DT]
FROM [OtherProjects]
UNION SELECT [Project],[FP DT]
FROM [OtherProjects]
ORDER BY [MilestoneDt]

which produces the structure:
Project | MilestoneDt
ProjA | 6/01/1996
ProjA | 10/16/1996
ProjA | 1/1/1997
ProjB | 2/01/2004
ProjB | 3/5/2004
ProjB | 4/18/2004
etc.

however, I would like to have another column (MilestoneDescription) describe
what each "row" is"

Project | MilestoneDt | MilestoneDescription
ProjA | 6/01/1996 | DueDate
ProjA | 10/16/1996 | PA DT
ProjA | 1/1/1997 | FP DT
ProjB | 2/01/2004 | DueDate
ProjB | 3/5/2004 | PA DT
ProjB | 4/18/2004 | FP DT

Any thoughts on how to get the other column?
JRW

Help indicates that you can do it this way (I didn't test it):

SELECT [Project],[Duedate] AS [MilestoneDt], 'Duedate' as MilestoneDescription
FROM [Datalock]
UNION SELECT [Project],[PA DT], 'PA DT'
FROM [OtherProjects]
UNION SELECT [Project],[FP DT], 'FP DT'
FROM [OtherProjects]
ORDER BY [MilestoneDt]



HTH
 
Thanks. It worked.

JRW said:
I want to combine multiple columns (from two diff tables) into one column
and have another column "describe" what the new row is. I currently have:

SELECT [Project],[Duedate] AS [MilestoneDt]
FROM [Datalock]
UNION SELECT [Project],[PA DT]
FROM [OtherProjects]
UNION SELECT [Project],[FP DT]
FROM [OtherProjects]
ORDER BY [MilestoneDt]

which produces the structure:
Project | MilestoneDt
ProjA | 6/01/1996
ProjA | 10/16/1996
ProjA | 1/1/1997
ProjB | 2/01/2004
ProjB | 3/5/2004
ProjB | 4/18/2004
etc.

however, I would like to have another column (MilestoneDescription) describe
what each "row" is"

Project | MilestoneDt | MilestoneDescription
ProjA | 6/01/1996 | DueDate
ProjA | 10/16/1996 | PA DT
ProjA | 1/1/1997 | FP DT
ProjB | 2/01/2004 | DueDate
ProjB | 3/5/2004 | PA DT
ProjB | 4/18/2004 | FP DT

Any thoughts on how to get the other column?
JRW

Help indicates that you can do it this way (I didn't test it):

SELECT [Project],[Duedate] AS [MilestoneDt], 'Duedate' as MilestoneDescription
FROM [Datalock]
UNION SELECT [Project],[PA DT], 'PA DT'
FROM [OtherProjects]
UNION SELECT [Project],[FP DT], 'FP DT'
FROM [OtherProjects]
ORDER BY [MilestoneDt]



HTH
 
Back
Top