请帮忙?

azsoft 2003-12-20 03:54:19
t
a v(int)
------------
1 0
2 3
3 4
4 0


结果
a v
-------------
1 -
2 3
3 4
4 -
...全文
35 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
美丽心情 2003-12-20
  • 打赏
  • 举报
回复
在此贴,偶学会了CASE,做个记号,谢谢~~

简单 CASE 函数:

CASE input_expression
WHEN when_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
]
END

CASE 搜索函数:

CASE
WHEN Boolean_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
]
END

美丽心情 2003-12-20
  • 打赏
  • 举报
回复
来学习的
dlpseeyou 2003-12-20
  • 打赏
  • 举报
回复
select id, case cast(应收增加 as varchar(10)) when '0' then '-'
else cast(应收增加 as varchar(10)) end
from test
victorycyz 2003-12-20
  • 打赏
  • 举报
回复

这个最好是在前台做显示格式。不要在查询时做。查询语句这样就行:select * from t
txlicenhe 2003-12-20
  • 打赏
  • 举报
回复
测试:
create table t1(a int,v int)
insert t1 values(1,0)
insert t1 values(2,3)
insert t1 values(3,4)
insert t1 values(4,0)

select a,(case when v = 0 then '-' else cast(v as varchar) end) as v
from t1

a v
----------- ------------------------------
1 -
2 3
3 4
4 -

(所影响的行数为 4 行)

dlpseeyou 2003-12-20
  • 打赏
  • 举报
回复
select a,case when v=0 then convert(varchar(4),'-')
else v end v from table order by a
dlpseeyou 2003-12-20
  • 打赏
  • 举报
回复
select a,case when v=0 then convert(varchar(4),'-')
else v end v order by a
yoki 2003-12-20
  • 打赏
  • 举报
回复
select a,case a when 0 then '-' else a end as v
from t
txlicenhe 2003-12-20
  • 打赏
  • 举报
回复
select a,(case when v = 0 then '-' else cast(v as varchar) end) as v
from 表
azsoft 2003-12-20
  • 打赏
  • 举报
回复
select kcbl=case
when isnull(kc,0)<>0
then
case
when isnull(xs,0)<>0 then
isnull(kc,0)/isnull(xs,0)
else
begin
'-'
end
end
else
0
end
from t

为啥不行?

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧