日期:2014-05-17  浏览次数:20464 次

按对应关系替换带分号的字符串

我这有一个关系对应表,另有一个字段存为ycord字段的组合如‘1;2;5’现在我要根据typeid把相应的gcord组合取到,举例:如果是typeid=6 那么‘1;2;5’就应该是‘1004、1012、1026’
typeid ycord gcord
6 2 1012
6 3 1013
6 5 1026
6 4 1027
6 4 1028
4 2 1012
4 3 1013
4 5 1026
4 4 1027
4 4 1028
7 2 6003
7 3 6003
7 5 6005
3 1 23011
3 2 23012
3 3 23013
3 4 23014
3 5 23015
2 1 3003
2 2 3010
2 3 3011
2 5 3023
2 4 3024
6 1 1004
4 1 1004
7 1 6006
7 4 6011
如何用SQL语句实现,请各位帮忙

------解决方案--------------------
declare @str varchar(10)='1;2;5'
select * from tb where typeid=6 and charindex(';'+rtrim(ycord)+';',';'+@str+';')>0