Hello Michael,
you should code your query this way:
FROM
[' + @dbname + '].DBO.DEF AS DEF
INNER JOIN [' + @dbname + '].DBO.SDE_CONFIDENTIALITY AS SDE_CONFIDENTIALITY
on DEF.SDE_CONFIDENTIALITY_CD = SDE_CONFIDENTIALITY.SDE_CONFIDENTIALITY_CD
WHERE
SDE_CONFIDENTIALITY.VALID_IND = '''...