读书人

在将 varchar 值 #039;6,7,8,9,20,21#039; 转换

发布时间: 2012-05-15 14:35:29 作者: rapoo

在将 varchar 值 '6,7,8,9,20,21' 转换成数据类型 int 时失败。
select * from table1 where id in (select id1s from table2 where id2=1)
id1是int类型的,id1s是varchar类型的

[解决办法]

SQL code
declare @str varchar(100)select @str = id1s from table2 where id2=1select * from table1 where charindex(','+ltrim(id)+',',','+@str+',') > 0 

读书人网 >SQL Server

热点推荐