请问sql server里什么方法能判断一个字段是否为空并返回布尔值

weixin_39402825 2017-09-11 10:44:52
新手小白一个求教大神们 用office写的iif语句换到sql server上要怎么实现啊
比如 iif(isNull(a.nian),1,2)
...全文
2382 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_39402825 2017-09-11
  • 打赏
  • 举报
回复
引用 6 楼 appetizing_fish1 的回复:
[quote=引用 5 楼 weixin_39402825 的回复:] [quote=引用 4 楼 appetizing_fish1 的回复:] 可以这样


case when A.Date is null 
     then  A.Date 
	 else case when IsDate(A.Date)=1
               then Format(DateAdd(month,-3,A.Date),'yyyy')
               else Format(DateAdd(month,-3,Left(A.Date,4)+'/4/1'),'yyyy')
			   end
	 end


谢谢大神 [/quote] 不用谢, 记得结贴啊.[/quote] 好的不说真忘了 第一次来 谢谢哈
顺势而为1 2017-09-11
  • 打赏
  • 举报
回复
引用 5 楼 weixin_39402825 的回复:
[quote=引用 4 楼 appetizing_fish1 的回复:] 可以这样


case when A.Date is null 
     then  A.Date 
	 else case when IsDate(A.Date)=1
               then Format(DateAdd(month,-3,A.Date),'yyyy')
               else Format(DateAdd(month,-3,Left(A.Date,4)+'/4/1'),'yyyy')
			   end
	 end


谢谢大神 [/quote] 不用谢, 记得结贴啊.
weixin_39402825 2017-09-11
  • 打赏
  • 举报
回复
引用 4 楼 appetizing_fish1 的回复:
可以这样


case when A.Date is null 
     then  A.Date 
	 else case when IsDate(A.Date)=1
               then Format(DateAdd(month,-3,A.Date),'yyyy')
               else Format(DateAdd(month,-3,Left(A.Date,4)+'/4/1'),'yyyy')
			   end
	 end


谢谢大神
顺势而为1 2017-09-11
  • 打赏
  • 举报
回复
可以这样


case when A.Date is null 
     then  A.Date 
	 else case when IsDate(A.Date)=1
               then Format(DateAdd(month,-3,A.Date),'yyyy')
               else Format(DateAdd(month,-3,Left(A.Date,4)+'/4/1'),'yyyy')
			   end
	 end


weixin_39402825 2017-09-11
  • 打赏
  • 举报
回复
引用 1 楼 yenange 的回复:
case when a.nian is null then 1 else 2 end
谢谢 请问这个是只能判断是否为null吗 我想在else 后面再加个 case when 然后想继续判断是否为日期的话呢 请问有方法能实现吗 求教谢谢了
case when A.Date is null then  A.Date else case when IsDate(A.Date) 
then Format(DateAdd('m',-3,A.Date),'yyyy'),
else Format(DateAdd('m',-3,Left(A.Date,4)+'/4/1'),'yyyy')))
  • 打赏
  • 举报
回复
CASE WHEN ISNULL(a.nian,NULL) IS NULL THEN 0 ELSE 1 END
吉普赛的歌 2017-09-11
  • 打赏
  • 举报
回复
case when a.nian is null then 1 else 2 end

11,848

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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