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
 General SQL Server Forums
 New to SQL Server Programming
 How to order a column logic

Author  Topic 

insanepaul
Posting Yak Master

178 Posts

Posted - 2012-04-12 : 10:58:26
These are strings in the table under column xmlTransaction and they can be in any order:

<Person update >
<Person insert >
<CPAdress update >
<CPAdress insert >
<Person update >
<Person insert >
<CPAdress update >
<CPAdress insert >

I always need all the <Person insert > to be at the top and
It doesn't matter about the others.

If I order by xmlTransaction I get CPAdress before Person
If I order by xmlTransaction desc I get Person update

I could just get the Person Inserts then the person updates then CPAaddress but thats a bit of an effort and I don't know how to escape the = and quote marks as the full string is:
<Person ActionType="Insert"

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-04-12 : 11:26:29
quote:
Originally posted by insanepaul

I always need all the <Person insert > to be at the top and
It doesn't matter about the others.



ORDER BY CASE WHEN xmlTransaction like '<Person Insert%' THEN 0 ELSE 1 END
Go to Top of Page

insanepaul
Posting Yak Master

178 Posts

Posted - 2012-04-12 : 11:32:22
Thanks for the help
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-04-12 : 12:26:57
You're welcome. :)
Go to Top of Page
   

- Advertisement -