![]() ![]() |
|
探讨SQLServer中Case的不同用法 | |
作者:佚名 文章来源:不详 点击数 更新时间:2007/10/21 20:28:33 文章录入:杜斌 责任编辑:杜斌 | |
|
|
首先让我们看一下 case 的语法。在一般的 select 中,其语法如下: select <mycolumnspec> = case when <a> then <somethinga> when <b> then <somethingb> else <somethinge> end 在上面的代码中需要用具体的参数代替尖括号中的内容。下面是一个简单的例子: use pubs go select title, 'price range' = case when price is null then 'unpriced' when price < 10 then 'bargain' when price between 10 and 20 then 'average' else 'gift to impress relatives' end from titles order by price go |
|
![]() ![]() |