Coalesce在SQL Server中不工作

编程入门 行业动态 更新时间:2024-10-22 16:50:57
本文介绍了Coalesce在SQL Server中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Select tbl_login.userid,tbl_login.name as Employee, (case when Exists(Select * from tbl_attendance where tbl_attendance.userid=tbl_login.userid and tbl_attendance.firstlogin is not null and tbl_attendance.date=''2011/03/25'') then ''Present'' else ''Absent'' end) as Status, (select top 1 COALESCE(tbl_timesheet.description,''Idle'') from tbl_timesheet where tbl_timesheet.userid=tbl_login.userid and date=''2011/03/25'' and stoptime is null) as Filename from tbl_login where tbl_login.privilege <> ''ADMIN''

其给定描述字段为NULL(如果为null,则不给定"Idle"),即(COALESCE)不起作用 任何人都可以帮忙吗

its giving description field as NULL(if its null,not giving ''Idle''),that is (COALESCE) is not working Can Anyone help

推荐答案

可能是问题出在您的where子句中.没有什么比它匹配的?如果描述为NULL,则返回空闲",但是如果在给定日期没有记录与用户ID匹配,该怎么办? It might be that the problem is your where clause. What is nothing matches it? ''Idle'' is returned if description is NULL, but what if there is no record that matches the userid at a given date? (select top 1 COALESCE(tbl_timesheet.description,''Idle'') from tbl_timesheet where tbl_timesheet.userid=tbl_login.userid and date=''2011/03/25'' and stoptime is null) as Filename

您需要将COALESCE包裹在完整的选择周围.

You need to wrap the COALESCE around the complete select.

COALESCE(select top 1 tbl_timesheet.description from tbl_timesheet where tbl_timesheet.userid=tbl_login.userid and date='2011/03/25' and stoptime is null, 'Idle') as Filename

祝你好运!

Good luck!

更多推荐

Coalesce在SQL Server中不工作

本文发布于:2023-10-07 14:20:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   工作   Coalesce   SQL   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!