declare @a int declare @b int select * from table where id between @a and @b 这样?
忘排序了 从小到大ASC 从大到小DESCdeclare @a int declare @b int select * from table where id between @a and @b order by id ASC
select * from table where id between 5 and 9
如实是LS的,岂不是太简单了,LZ是这意思?
--这样?--问题太简单了?select * from 表名 where id between 100 and 200
LZ是这意思吗? 呵呵,LZ快回答吧,虽然我写了答案,但也不是很相信。
select * from tb where id >= @id1 and id <= @id2select * from tb where id between @id1 and @id2
declare @m int, @n int select @m=2, @n=10 select * from tb where id between @m and @n
又in比较好吧 select * from tb where id in(@M,@n)
create table tb(id varchar(8))insert tb select '2' union all select '4' union all select '5' union all select '006' union all select '7' union all select '8'declare @m int, @n int select @m=2, @n=7 select * from tb where id between @m and @ndrop table tb/* id -------- 2 4 5 006 7(5 row(s) affected) */
declare @a varchar(4) declare @b varchar(4)select * from tb where id between cast(@a as int) and cast(@b as int) order by cast(id as int)ASC这样呢?
字符型按数值比较,还是按字符比较? 如果按字符比较:select * from 表名 where id between '100' and '200'如果按数值比较,需要先转换一下:select * from 表名 where id between cast('001' as int) and cast('00200' as int)
select * from tb where id >= @id1 and id <= @id2 select * from tb where id between @id1 and @id2
declare @b int
select * from table where id between @a and @b
这样?
declare @b int
select * from table where id between @a and @b order by id ASC
from 表名
where id between 100 and 200
呵呵,LZ快回答吧,虽然我写了答案,但也不是很相信。
select @m=2, @n=10
select * from tb where id between @m and @n
select * from tb where id in(@M,@n)
union all select '4'
union all select '5'
union all select '006'
union all select '7'
union all select '8'declare @m int, @n int
select @m=2, @n=7
select * from tb where id between @m and @ndrop table tb/*
id
--------
2
4
5
006
7(5 row(s) affected)
*/
declare @b varchar(4)select * from tb where id between cast(@a as int) and cast(@b as int)
order by cast(id as int)ASC这样呢?
如果按字符比较:select *
from 表名
where id between '100' and '200'如果按数值比较,需要先转换一下:select *
from 表名
where id between cast('001' as int) and cast('00200' as int)