Ò»¸ö×Ö¶ÎÊÇÕâÑùµÄ 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 ----- Õâ¸ö×Ö¶ÎÊDZ£´æ1¡£..9 µÄÊý¾Ý µ«ÊdzÌÐò´«¹ýÀ´µÄÊý¾ÝÊÇ 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