27,579
社区成员
发帖
与我相关
我的任务
分享
--如果一定要用这个不合理的表,如下:
--> 测试数据: [tb]
if object_id('[tb]') is not null drop table [tb]
create table [tb] (df int,xj int,qk int)
insert into [tb]
select 100,0,0 union all
select 0,200,0 union all
select 0,0,300
--开始查询
select
case
when df <> 0 then '到付'
when xj <> 0 then '现金'
when qk <> 0 then '欠款'
else ''
end
from tb
--结束查询
drop table [tb]
/*
----
到付
现金
欠款
(3 行受影响)
[Quote=引用 4 楼 twtxrjso 的回复:]
建议你提供详细的资料:
例如表的结构,表之间的关系,测试数据,相关算法及需要的结果。
这样有助于我们理解你的意思,更主要的是能尽快让你获得答案或解决问题的方法。
select case when a <> 0 then '到付' else '' end,
case when b <> 0 then '现金' else '' end,
case when c <> 0 then '欠款' else '' end
from tb