一个字段是这样的 x 可以放多个值.. 传进来是字符串, ==> 12,13,14...20 如 select * from tableName where x in(12,13,14...20) 原始数据是这样..但是我想要得到 select * from tableName where x in(1,2,3...9)
也就是在原来的基础上减去11 ---?>>select * from tableName where x in(1,2,3...9)
没看明白 ,帮顶。
贴出表结构,数据
以及你要的结果
参考以下
SQL code:
create table #t(
id varchar(10))
declare @str varchar(300)
set @str='12,13,14,20'
declare @i int
declare @len int
set @i = 1
while @i < len(@str+',')
begin
insert #t select substring(@str+',',@i,charindex(',',@str+',',@i)-@i)
set @i = charindex(',',@str+',',@i)+1
end
select * from #t
/*
id
----------
12
13
14
20
(所影响的行数为 4 行)
*/
--drop table #t
create table a
(
id int identity(1,1) not null,
x int not null ----- 这个字段是保存1。..9 的数据 但是程序传过来的数据是 12,13,14...20 一个字符串
)
insert into a select 1 union all select 2 union all select 3 ,,,union all select 9
SQL code:
id varchar(10))
declare @str varchar(300)
set @str='12,13,14,20'
declare