FROM
Table1 L
LEFT JOIN
Table2 M ON L.id = M.id
AND ISNULL([Col1], '') NOT IN ('', '#N/A', 'NULL')
如何在T-SQL中编写此逻辑,我想要排除null,NA以及字符串NULL?
答案 0 :(得分:0)
两种可能性是使用where
子句(也是本主题的标题所示),或者删除left
连接。
SELECT ...
FROM Table1 L
JOIN Table2 M ON L.id = M.id
AND ISNULL([Col1],'') NOT IN ('','#N/A','NULL')
SELECT ...
FROM Table1 L
JOIN Table2 M ON L.id = M.id
WHERE ISNULL([Col1],'') NOT IN ('','#N/A','NULL')
答案 1 :(得分:0)
SELECT *
FROM Table1 L
LEFT JOIN Table2 M
ON L.id = M.id
AND
M.id IS NOT NULL
AND
NOT(L.[Col1] IN ('#N/A', 'NULL'))
SELECT *
FROM (SELECT * FROM Table1 WHERE NOT(Table1.[Col1] IN ('#N/A', 'NULL'))) L
LEFT JOIN Table2 M
ON L.id = M.id
AND
M.id IS NOT NULL