Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要帮助来构建一个选择不同条件的查询。例如:
SELECT EMP, COD, VEV, GRU, (SELECT DISTINCT CAST(EMP , CHAR(20) ) + CAST(COD , CHAR(20) ) AS CONCAT FROM HCOV WHERE GRU = 212 ) FROM HCOV
在此示例中,如果 GRU = 212,我需要连接 EMP 和 COD 列,然后删除重复项
但是我的“Concat”列带来了空值而不是连接。
请帮忙
我很惊讶您的查询没有出错,因为子查询返回不止一行。无论如何,看起来您根本不需要子查询。这不是你想要的吗?
select emp, cod, vev, gru, case when gru = 212 then concat(cast(emp as char(20)), cast(cod as char(20))) end as res from hcov