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 |
|
jdbargas
Starting Member
1 Post |
Posted - 2008-08-04 : 17:58:30
|
| Hi all,I have two queries that return results that i need to be able to put into one query. SELECT Id, TermDescFROM TermsWHERE (Id LIKE '%/%') AND (TermDesc NOT LIKE '%Nursing%')ORDER BY TermStartDateThis returns these values:Fall 2007Winter 2008Spring 2008Summer 2008Fall 2008Winter 2009Spring 2009Summer 2009The next query:SELECT Id, TermDescFROM TermsWHERE (Id NOT LIKE '%/%') OR (TermDesc LIKE '%Nursing%')ORDER BY TermStartDateReturns similar results, with a distint orderCAPE ECE #19 CLEARLAKECAPE BSM #31 NAPADCP ECE #20 NAPADCP BSM #32 NAPADCP ECE #21 SANTA ROSAI need a query that can join these and retain their separate orders to end up with results like this:Fall 2007Winter 2008Spring 2008Summer 2008Fall 2008Winter 2009Spring 2009Summer 2009CAPE ECE #19 CLEARLAKECAPE BSM #31 NAPADCP ECE #20 NAPADCP BSM #32 NAPADCP ECE #21 SANTA ROSAEverything I've tried results in the orders getting mixed and I can't have that. Any ideas would be great! Thanks in advance for the help!-Jordan |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2008-08-04 : 19:21:16
|
| SELECT Id, TermDescFROM(SELECT Id, TermDesc, TermStartDate, 1 as SortOrderFROM TermsWHERE (Id LIKE '%/%') AND (TermDesc NOT LIKE '%Nursing%')UNION SELECT Id, TermDesc, TermStartDate, 2 as SortOrderFROM TermsWHERE (Id NOT LIKE '%/%') OR(TermDesc LIKE '%Nursing%')) aORDER BY SortOrder, TermStartdate |
 |
|
|
|
|
|