开发者

I'm trying to run a query in SQL and I want to know why ADDRESS_LINE_2 is over taking ADDRESS_LINE_1 and showing null

开发者 https://www.devze.com 2023-01-24 03:08 出处:网络
SELECT EMPLOYEE.EMPLOYEE_FNAME + EMPLOYEE.EMPLOYEE_LNAME + EMPLOYEE.EMPLOYEE_PRIMARY_NUMBER + EMPLOYEE.EMPLOYEE_EMAIL AS EMPLOYEE,
SELECT    
   EMPLOYEE.EMPLOYEE_FNAME + EMPLOYEE.EMPLOYEE_LNAME +    
         EMPLOYEE.EMPLOYEE_PRIMARY_NUMBER + EMPLOYEE.EMPLOYEE_EMAIL AS EMPLOYEE, 
  ADDRESS.ADDRESS_LINE_1开发者_Go百科 + ADDRESS.ADDRESS_LINE_2 + ADDRESS.CITY_PROVINCE +   
         ADDRESS.STATE_ABBREVIATION + ADDRESS.POSTAL_CODE AS ADDRESS
FROM         
   EMPLOYEE 
INNER JOIN
  ADDRESS ON EMPLOYEE.ADDRESS_ID = ADDRESS.ADDRESS_ID


You need to ensure that no data is null

isnull(ADDRESS.ADDRESS_LINE_1, '') 
+ isnull(....


If you concatenate a string and a null value, the result is null.

Use coalesce or isnull to make sure that you don't have a null value:

ADDRESS.ADDRESS_LINE_1 + COALESCE(ADDRESS.ADDRESS_LINE_2, '')


You can override the default options for null concatenation with this:

SET CONCAT_NULL_YIELDS_NULL OFF
0

精彩评论

暂无评论...
验证码 换一张
取 消