I have a procedure and a COMMON TABLE EXPRESSION (subquery). This my CTE does a search and offers to my query the result, my query then uses the results of it.
In my Address table I have a "Complement" field that allows null values. However when my CTE does the query and compares with the @complemento if the complement is empty, the result of the CTE returns nothing, even the NULL value existing in the pendant_table, otherwise the reverse if it looks for a record whose complement is filled the search finds.
I'll show you the code and the error.
Note 1: The error happens because FK does not accept null values and because the subquery returns null value, this error happens. Note 2: The other procedure after the EXEC only registers addresses.