Link to home
Start Free TrialLog in
Avatar of martyje
martyje

asked on

How to sort an nvarchar field that contains special characters

I am trying to sort a field that has special characters in them .i.e. `, ", ' etc
When I sort the results, the records with special characters always show up first, is there any way to ignore special characters during the sort, in SQL Server maybe? or in PHP if not.

Thanks.
.i.e. `, ", ' etc

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of martyje
martyje

ASKER

How do I get rid of double qoutes and single qoutes?
It works fine with ` but gives error on double qoutes and single qoutes.
Thanks much.
single quotes:
replace(fieldname, '''', '')

double quotes:

replace(fieldname, '''''', '')
Avatar of martyje

ASKER

Sorry guys, I have to keep the single qoutes/double qoutes and all the speical characters in there and then sort it. Is there any way to not to take them out but ignore them while sorthing.

Thanks much.
You're not taking them out...you're just taking them out of the sort....just like angelIII showed you.  You're ignoring them....make sure your REPLACE statement is after the ORDER BY clause.
Avatar of martyje

ASKER

You rock... Thanks much.