By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

Sorting

OuTCasT
100+
P: 374
I have been asked to rearrange the data in a table to display from

Region Contacts
---------------------------------------
Cape Town John
Cape Town Ruby
Cape Town Anna
Durban Joe
Durban Allison
Johannesburg Derrick


To This

Region Contacts
----------------------------------------
Durban Joe
Durban Allison
Johannesburg Derrick
Cape Town Anna
Cape Town Ruby
Cape Town John
Jan 6 '10 #1
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
I can't see any logical order in your example.
Can you be more specific?
Jan 6 '10 #2

OuTCasT
100+
P: 374
They gave me 2 columns to sort...
Region and Contacts

That is what is on the sheet, the original is the top data, now they said write sql query to rearrange the data in the new order which is at the bottom.

I dunno if that is possible. I also looked and there is no logical order of the data.

Kind Regards
D.Kruger
Jan 6 '10 #3

nbiswas
100+
P: 149
The closest I can think of is

Expand|Select|Wrap|Line Numbers
  1. select Region,Contacts from @t  where region not like '% %'
  2. union all
  3. select Region,Contacts from @t  where region like '% %'
Output:

Expand|Select|Wrap|Line Numbers
  1. Region    Contacts
  2. Durban    Joe
  3. Durban    Allison
  4. Johannesburg    Derrick
  5. Cape Town    John
  6. Cape Town    Ruby
  7. Cape Town    Anna
Jan 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.