如何选择转换列表varchar WHERE IN()SQL查询
select code from table1
Code
10223
10240
10047
10174
10187
10192
10212
10213
10195
select * table2 from where code in
('10047','10174','10187','10192','10212','10213','10195')
我需要这个
的存储过程答案 0 :(得分:2)
in
运算符可以对查询进行操作,因此无需进行此类转换:
SELECT *
FROM table2
WHERE code IN (SELECT code FROM table1)
答案 1 :(得分:0)
您有两种选择:
假设Code
中的table1
列是唯一的:
SELECT t2.* FROM table2 t2 INNER JOIN table1 t1 ON CAST(t1.code AS VARCHAR)=CAST(t2.code AS VARCHAR)
SELECT * FROM table2 WHERE code IN
(SELECT code FROM table1)