select * from A where cid in (
select ''''+replace(cinstrumentid,',',''',''')+'''' as dd from B
where iautoid='7873'
)如果用下面的语就能结果,
直接走select ''''+replace(cinstrumentid,',',''',''')+'''' as dd from B where iautoid='7873'的结果也是 'AA1','BB','CC',为什么上面的就没结果了????
select * from A where cid in(
'AA1','BB','CC'
)
select cinstrumentid from B where iautoid='7873'
)实践出不行.
select cinstrumentid from B where iautoid='7873'
上面这句结果是AA1,BB,CC
select ltrim(rtrim(cinstrumentid)) from B where iautoid='7873'
)
还是不行
cid 和cinstrumentid 都是varchar
你拿它与这样一个语句去比较一下:
select * from tb where cid in('AA','BB','CC')
这后面括号中,是三个字符串序列,而不是一个字符串!如果你的cid中不包含 'AA','BB','CC' 这样一个包含引号的一串字符,而不是仅仅为 'AA' 或 'BB' 或'CC' 这样的三个字符串之一的话,那你就查不出结果来。