如果value为null或为空,则组合两个表 [英] To combine two table if value is null or empty

查看:69
本文介绍了如果value为null或为空,则组合两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家

i有两个地址表,如Address1和CommonAddress



地址1有Line1,Line2,Country,State,Zip

CommonAddress有Line1,Line2,State



i想要sql查询如果State在Address1表中为null,它将在CommonAddress中用State替换同名行1



请帮帮我









提前致谢..

解决方案

COALESCE() [ ^ ]是您想要使用的。它将返回第一个非空值。



例如:

  SELECT   COALESCE (a.State,c.State) AS 状态, COALESCE (a.line1,c.line1) AS  line1等... 
FROM 地址1 a
LEFT JOIN CommonAddress c ON ...无论您的 join 是< /跨度>


Hi experts
i have two address tables like Address1 and CommonAddress

Address1 have Line1,Line2,Country,State,Zip
CommonAddress have Line1,Line2,State

i want sql query for if State is null in Address1 table it will be replace with State in CommonAddresswhen getting with same name of line1

please help me




Thanks in advance..

解决方案

COALESCE()[^] is what you want to use. It will return the first non-null value.

For example:

SELECT COALESCE(a.State, c.State) AS State, COALESCE(a.line1, c.line1) AS line1, etc...
FROM Address1 a
LEFT JOIN CommonAddress c ON ... whatever your join is


这篇关于如果value为null或为空,则组合两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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