SQL Server 中的排序顺序 [英] Sort Order in SQL Server

查看:38
本文介绍了SQL Server 中的排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能否更改 SQL Server 数据库中的默认排序顺序,以便最后显示空值和零长度字符串.

Can I change the default sort order in a SQL server database so that nulls and zero length strings are displayed last.

它的 SQL Server 2000

Its SQL Server 2000

我强调,如果可能,我想更改所有查询的默认顺序

I stress, I want to change the default order for all queries, if possible

推荐答案

您几乎可以使用 caseorder by 中进行任何排序.首先是 null 列,然后是空字符串,其余的列在 col1 和 col3 上:

You can do almost any sort using a case in an order by. Here's the null columns first, then the empty strings, and the rest ordered on col1 and col3:

select  *
from    YourTable
order by
        case when col1 is null then 1
             when col1 = '' then 2
             else 3
        end
,       col2
,       col3 desc

这篇关于SQL Server 中的排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆