I must be missing something. I have the following code that formats a data row into a | separated string. It is checking for NULLs but on one row it seems to ignoring that fact. The underlined lines were added for debugging proposes.SET NOCOUNT ON SELECT --DISTINCT --TOP 500000 ISNULL(CONVERT(VARCHAR(50), CUST_EDP), '') + '|' + CONVERT(VARCHAR(255), RTRIM(LTRIM(ISNULL([ADDRESS1], '')))) + '|' + CONVERT(VARCHAR(255), RTRIM(LTRIM(ISNULL([ADDRESS2], '')))) + '|' + CONVERT(VARCHAR(255), RTRIM(LTRIM(ISNULL([CITY], '')))) + '|' + CONVERT(VARCHAR(255), RTRIM(LTRIM(ISNULL([STATE_CD], '')))) + '|' + CONVERT(VARCHAR(255), RTRIM(LTRIM(ISNULL([POSTAL_CD], '')))) + '|' + [USCAN_CD] AS Formatted_String , LEN(CONVERT(VARCHAR(255), RTRIM(LTRIM(ISNULL([ADDRESS1], ''))))) AS LENAddress1 , CONVERT(VARBINARY, [ADDRESS1]) AS BinAddress1 FROM [NameSearch_Customer_BaseList_RecordsToProcess] WHERE USCAN_CD IN ('USA', 'CAN') AND ISNULL([ADDRESS1], '') <> '' AND ISNULL([CITY], '') <> '' AND ISNULL([STATE_CD], '') <> '' AND ISNULL([POSTAL_CD], '') <> '' AND CUST_EDP IN (2328587, 2204406) ORDER BY USCAN_CD SET NOCOUNT OFF
The output is shown below. It seems that even though there are no character values for ADDRESS1 the second line a) still shows a length of 30 and b) is not responding to the ISNULL directive.EDIT: It appears I have 12 rows with this situation in my table.Formatted_String LENAddress1 BinAddress12204406|150 E 69TH ST APT 3P||NEW YORK|NY|100215722|USA 20 0x3135302045203639544820535420415054203350202020202020202020202328587| |782|6611 E 129TH AVE|TH|CO|USA 30 0x000000000000000000000000000000000000000000000000000000000000
Does anyone have any ideas as to what's going on here?Thanks