Groups | Blog | Home
all groups > sql server clients > october 2003 >

sql server clients : ORDER BY should ignore HTML tags while sorting


denzilpereira NO[at]SPAM lycos.com
10/1/2003 4:07:23 AM
Hi...

I need to sort (ORDER BY) the data in a table alphabetically. Now it
may so happen that the data could contain HTML tags embedded and the
special first char "<" of the HTML opening tag is used for the ORDER
BY clause and hence in the following sample of data I have, I always
have <B>Tiger</B> as the first row.

I need to escape just the HTML tags (<B> in this case and also double
quotes) for my ORDER BY... What's the best way to achieve this...

Original Table data
Data in Column1 - Dog
Data in Column2 - <B>Tiger</B>
Data in Column3 - Zebra

After doing a ORDER BY
<B>Tiger</B> --I need this to be the 2nd row ... i.e. ignore <B> for
the sort
Dog
Zebra

Any pointers/ suggestions will be appreciated.
Thanks for your time.

Cheerz...
John Bell
10/1/2003 12:49:50 PM
Hi

You may get away with something like:

SELECT Col
FROM MyTable
ORDER BY RIGHT(Col, LEN(Col)-PATINDEX('%>%',Col))

or maybe extensive use of the replace function. Another solution would be to
hold a clean version of the data.


John

[quoted text, click to view]

denzilpereira NO[at]SPAM lycos.com
10/2/2003 12:37:50 AM
Dear John...

Thanks a lot for ur help... Got another nice way of doing it... Thanks to u...

I tried the same using the following (REPLACE)...

<snip>
when (@TempStr = '<B>')
then replace (ltrim(rtrim(MyCol)), @TempStr, '')
<snip>


Cheerz...
Denzil

[quoted text, click to view]
AddThis Social Bookmark Button