Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 16th, 2004, 12:28 AM
epig epig is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 epig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb Multiple columns with UNION?

I've got a DB with six tables, one for patient details, and five with results from five different (paper) forms. Each form can be filled out more than once and is indexed according to the patient id and the date it was completed. Therefore, one patient could complete a differing number of each forms.

I'm trying to design a query that will list the patient number in one column, and the dates that the forms were completed in five separate columns corresponding to the form type. In other words, for a particular patient there could be 1 record of form A, 5 records of form B, 2 records of form C, etc.. I've run various queries (using grouping), but this creates cascading duplicates; as well as a UNION query, but this puts all the dates into a single column (see below). Is there some way of generating the UNION results into separate columns corresponding to the form type?

SELECT Patients.[Patient ID], AQoL.Date
FROM Patients LEFT JOIN AQoL ON Patients.[Patient ID] = AQoL.[Patient ID];
UNION
SELECT Patients.[Patient ID], HSU.Date
FROM Patients LEFT JOIN HSU ON Patients.[Patient ID] = HSU.[Patient ID];
UNION
SELECT Patients.[Patient ID], KDQOL.Date
FROM Patients LEFT JOIN KDQOL ON Patients.[Patient ID] = KDQOL.[Patient ID];
UNION
SELECT Patients.[Patient ID], HUI.Date
FROM Patients LEFT JOIN HUI ON Patients.[Patient ID] = HUI.[Patient ID];
UNION SELECT Patients.[Patient ID], [Patient Diary].Date
FROM Patients LEFT JOIN [Patient Diary] ON Patients.[Patient ID] = [Patient Diary].[Patient ID];

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Multiple columns with UNION?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway