sql server - Is there any way to put an invisible character at beginning of a string to change its sort order? -


is there way put non printing or non obtrusive character @ beginning of string of data in sqlserver. when order by performed, string sorted after letter z alphabetically?

i have used space @ beginning of string string @ top of sorted list, looking similar put string @ end of list.

i rather not put field such "sortorder" in table use order sort, , rather not have sort list in code.

added: yes know bad idea, mentioning it, still, curious if asking can done

since no 1 venturing answer question properly, here's answer

given: adding <space> other data make them appear top

solution: add char(160) make appear @ bottom. in reality space, designed computer systems not treat word break (hence name).

http://en.wikipedia.org/wiki/non-breaking_space

your requirements:

  1. without adding field such "sortorder" table
  2. without sorting list in code

i think fits!

create table my(id int,data varchar(100)) insert select 1,'banana' union select 2,char(160) + 'mustappearlast' union select 3,' ' +n'mustappearfirst' union select 4,'apple' union select 5,'pear'  select * order ascii(lower(data)), data 

(ok cheated, had add ascii(lower( closest requirements other answers far)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -