sql server 2008 - Changing position of a row in sql -


enter image description here in above t-sql table total row appear @ bottom. have been wracking head against , in of other queries using order status works total alphabetically farther down list of our row values.

this not case here , can't figure out how change it

i'm pretty new sql , i'be been having lot of difficulty determining how phrase google search. far i've gotten results pertaining order

the results of select query, unless order explicitly specified via 'order by' clause, can returned in any order. moreover, order in returned not deterministic. running exact same query 3 times in succession might return exact same result set in 3 different orderings.

so if want particular order table, need order it. order clause like

select * mytable t ... order case status when 'total' 1 else 0 end ,          status 

would you. 'total' row float bottom, other rows ordered in collating sequence. can order things arbitrarily technique:

select * mytable t ... order case status            when 'deceased'  1            when 'total'     2            when 'active'    3            when 'withdrawn' 4            else                  5          end 

will list row(s) status of 'deceased' first, followed row(s) status of 'total', 'active' , 'withdrawn', , didn't match item in list.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -