Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Separate a Column to Three Columns?

Author  Topic 

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-09-17 : 07:19:33
How do I divide one column into three seperate ones with nested / sub queries? The where clause picks the three values I need to use, but I need each AttendanceType to be a column, with values of it's own - possibly grouping to summarise. Live a pivot table? To have the same columns either side, how do I do the parenthesis syntax to get this?

Thanks

select distinct
DG.PatientNumber,
AttendanceType,
PostCode,
AttendanceDate
from Demographic DG
inner join vrAttendance A on A.PatientNumber = DG.PatientNumber
inner join Diagnosis D on D.PatientNumber = DG.PatientNumber
where AttendanceType in ('New Patient','Follow-up (Old)','Rebook Patient')
and D.DiagnosisDate between '10-09-2009' and '17-09-2009'

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-17 : 07:28:38
So 2 of that 3 columns are always null or whatever?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-09-17 : 07:43:44
Rather than having
AttendanceType
Patient A New
Patient B Follow-up
Patient C Rebook
Patient D New

repeated.....

want to have

New Follow-up Rebook
A 1 2 2 zipcode...
B 1 0 1
C 1 0 0
D 1 5 3
------------------------------
4 7 6

is it necessary to nullify some columns?
Go to Top of Page

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-09-17 : 07:52:50
oh that did not lay out very nicely
Go to Top of Page
   

- Advertisement -