外键为','(逗号)拼接ID,连接查询外键表ID

select distinct  pipeId=substring(a.PipeIn,b.number,charindex(',',a.PipeIn+',',b.number)-b.number)

from B_PipeSet_Info a

join master..spt_values b on b.type='P'

where charindex(',',','+a.PipeIn,b.number)=b.number

 

你可能感兴趣的:(查询)