如何在嵌套查询中使用case语句? [英] How to use case statement in nested queries?

查看:81
本文介绍了如何在嵌套查询中使用case语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,

CASE(从员工中选择FirstName +''+ LastName,其中Id = p.MeetingWith)WHEN''THEN'经理(tbs)'结束为经理名称



这是我在storeprocedure中进行的一栏...我想要做的是..如果我的列名称为NULL或空白,那么我想将经理姓名显示为经理(tbs)否则我想显示经理姓名的结果

Hii,
CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END AS ManagerName

this is my one column i am retriving in storeprocedure... what i want to do is .. if my coming column name is NULL or blank then i want to show manager name as "manager(tbs)" else i want to display coming result of manager name

推荐答案

实际上,你可以使用COALESCE()。



尝试



Actually, you can just use COALESCE().

Try

SELECT COALESCE(FirstName + ' ' + LastName, 'manager(tbs)') AS ManagerName
FROM Employee
WHERE id = p.MeetingWith





COALESCE将返回它找到的第一个NON NULL值。所以,如果FirstName和LastName为NULL,那么你将得到'manager(tbs)'



COALESCE will return the first NON NULL value it finds. So, if FirstName and LastName IS NULL then you will get 'manager(tbs)'


你好,



所有你需要的要做的是将case语句嵌套如下:



Hi,

All you need to do is to nest the case statements as follows:

Case when CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END is null then 'manager(tbs)' when CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END='' then 'manager(tbs)' else CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END end as manager


这篇关于如何在嵌套查询中使用case语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆