关于select里加入条件判断的问题!!!!!!!!!!!!!

苯苯苯熊PK 2008-05-26 01:23:31
SQL如下
select fid,fnumber,case when fbilltype=2 then fnumber else '' end
from a
我要实现的是,当fbilltype=2时取fnumber字段的值否则取空值(fbilltype是数字型字段,fnumber是字符串)。我在执行时提示我类型不匹配,怎么回事?
我该怎么写这个SQL呢?
...全文
272 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2008-05-26
  • 打赏
  • 举报
回复
[Quote=引用楼主 wcjmecn 的帖子:]
SQL如下
select fid,fnumber,case when fbilltype=2 then fnumber else '' end
from a
我要实现的是,当fbilltype=2时取fnumber字段的值否则取空值(fbilltype是数字型字段,fnumber是字符串)。我在执行时提示我类型不匹配,怎么回事?
我该怎么写这个SQL呢?
[/Quote]

select fid,fnumber,case when fbilltype = 2 then fnumber else null end from a 

select fid,fnumber,case when fbilltype = 2 then cast(fnumber as varchar) else '' end from a
忆轩辕 2008-05-26
  • 打赏
  • 举报
回复
用case when实现
pt1314917 2008-05-26
  • 打赏
  • 举报
回复

select fid,fnumber,case when fbilltype=2 then ltrim(fnumber) else '' end
from a
arrow_gx 2008-05-26
  • 打赏
  • 举报
回复
select fid,fnumber,case when fbilltype=2 then cast(fnumber as varchar(100)) else '' end from a
Limpire 2008-05-26
  • 打赏
  • 举报
回复
select fid,fnumber,case when fbilltype=2 then ltrim(fnumber) else '' end from a
Limpire 2008-05-26
  • 打赏
  • 举报
回复
 select fid,fnumber,case when fbilltype=2 then ltrim(fnumber) else '' end from a
liangCK 2008-05-26
  • 打赏
  • 举报
回复
select fid,fnumber,case when fbilltype=2 then ltrim(fnumber) else '' end
from a

34,594

社区成员

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

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