加入时变为null [英] getting null in joining

查看:56
本文介绍了加入时变为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的sql中加入名字和姓氏

这是我的sql:

选择concat(FirstName,'',LastName)作为tablename的全名;

但是如果姓氏是空白的,那么我的名字就是null ...

但在这种情况下我想要名字,,,怎么做?

i have to join first name & last name in my sql
this is my sql :
select concat(FirstName,' ',LastName) as fullname from tablename;
but if last name is blank,then i am getting null as fullname..
but in that case i want first name ,,,how to do this??

推荐答案

尝试选择concat(ISNULL(FirstName,''),'',ISNULL(LastName,''))

ISNULL [ ^ ]将检查null并相应地返回一个值。
Try select concat(ISNULL(FirstName,''),' ',ISNULL(LastName,'')).
ISNULL[^] will check for null and return a value accordingly.


试试这个。

Try this.
select (Isnull(@fname,' ')+''+Isnull(@lastname,' ') ) as fullname ;  


试试这个

try This
select Trim(FirstName + ' ' + LastName) as fullname from tablename;






Or

select Trim(FirstName & ' ' & LastName) as fullname from tablename;



我不确定'+'和'&',所以请尝试两者,这将满足您的需求。


I am not sure about the '+' and '&', so try both and this will fulfill your need.


这篇关于加入时变为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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