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 |
asoltys
Starting Member
8 Posts |
Posted - 2008-05-23 : 13:44:39
|
Hello,I have a 'competencies' table and a 'categories' table. A competency has a name and a category_id. There are four categories altogether:'Core''Leadership''Knowledge''Other'I want to perform a query that will return a record set with the 'Core', 'Leadership', and 'Other' competencies listed alphabetically at the top followed by the 'Knowledge' competencies listed alphabetically at the bottom.Is this possible with a single query?Thanks,Adam |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-23 : 13:46:24
|
Can you illustrate your requirement with some sample data? |
 |
|
asoltys
Starting Member
8 Posts |
Posted - 2008-05-23 : 14:00:12
|
Sure,Let's say I have the following categories:id | name1 | Core2 | Leadership3 | Other4 | KnowledgeAnd I have these competencies:name | category_idAdaptability | 1Advice | 2Analytical Thinking | 3Client Focus | 2Consulting | 3Engagement | 1Influence | 2Initiative | 3Knowledge of management practices | 4Knowledge of acts and regulations | 4Knowledge of branch programs | 4Negotiating | 1Problem Management | 2I want to get a recordset ordered like this:AdaptabilityAdviceAnalytical ThinkingClient FocusConsultingEngagementInfluenceInitiativeNegotiatingProblem ManagementKnowledge of acts and regulationsKnowledge of branch programsKnowledge of management practicesThe thing to note is that everything is alphabetical regardless of category_id EXCEPT for the knowledges with category id of 4 which must appear at the bottom rather than in between 'Initiative' and 'Negotiation'.I hope this makes sense. Let me know if I need to clarify anything.Adam |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-23 : 14:15:19
|
[code]SELECT t.name FROM(SELECT name,category_id, case when category_id=4 then 2 else 1 end as OrderValueFROM competencies)t ORDER BY t.OrderValue,t.name[/code] |
 |
|
asoltys
Starting Member
8 Posts |
Posted - 2008-05-23 : 14:34:52
|
Thanks visakh, it worked great.Adam |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-26 : 06:04:22
|
or justSELECT name, case when category_id=4 then 2 else 1 end as OrderValueFROM competenciesORDER BY OrderValue,nameMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|