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.
Author |
Topic |
jarrette
Starting Member
4 Posts |
Posted - 2008-10-02 : 10:46:35
|
Hey all,Have a quick question concerning a DISTINCT SELECT from 2 columns.I have a doctor table that has, among others, 2 columns called specialty and specialty2. I need all distinct specialties from both columns.this doesn't work because it gives me all distinct combinations...SELECT DISTINCT Specialty, Specialty2FROM Pharma.Doctors dORDER BY Specialty.Net Developer |
|
jarrette
Starting Member
4 Posts |
Posted - 2008-10-02 : 11:01:54
|
NM, figured it out. Here is the solution for reference...ALTER PROCEDURE [Pharma].[GetSpecialties] @CompanyID intAS SELECT DISTINCT s.specsFROM(SELECT Specialty AS specs FROM Pharma.DoctorsWHERE CompanyID = @CompanyID OR CompanyID is nullUNION ALLSELECT Specialty2 AS specs FROM Pharma.DoctorsWHERE CompanyID = @CompanyID OR CompanyID is null)sORDER BY s.specs.Net Developer |
|
|
|
|
|