比如 值1:10001 值2:10005结果
10002
10003
10004
10002
10003
10004
解决方案 »
- 自动记录前台Delphi操作
- sqlserver能不能像access那样客户端不用启动servers?
- 请教 Sql Server 用递归取得上一级的数据.
- 请大虾帮个库存的问题
- 求一条查询语句
- 我在数据库中自己生成一个按指定规则生成的编号,我怎么保证自己这个编号被申请好后,在别的用户申请时不把该编号提供给别的用户呢?
- SQL中如何删除指定时间前的数据
- 我想问一下:在DELPHI中,如何连接数据库SQL SERVER 2000?
- 请问几个ORACLE方面的问题(高手请进!)
- 请问SQL2000的管理工具中有没有监视某个DataBase的某个Table变化情况的功能?
- 导数据问题
- 怎样外键关联两个表?
from tb
where 列1 > 值1 and 列1 < 值2
declare @s table (a int)
set @n1=10001
set @n2=10005
while(@n1<@n2-1)
begin
insert @s values(@n1+1)
set @n1=@n1+1
end
select * from @s
/*
a
-----------
10002
10003
10004
*/
from master..spt_values
where type = 'P'
and @s + number between @s and @e
declare @n1 int ,@n2 int
set @n1=10001
set @n2=10005
select @n1 + number as K
from master..spt_values
where type = 'P'
and @n1 + number > @n1 and @n1 + number <@n2/*
K
-----------
10002
10003
10004
*/
这个没注意 到,汗
where type = 'P'
and @n1 + number between @n1+1 and @n2-1
sqlserver2005有没有函数 select 某函数(v1,v2)实现同样的功能?
create function dbo.f_jj(
@n1 int ,@n2 int)
returns @s table (a int)
as
begin
while(@n1<@n2-1)
begin
insert @s values(@n1+1)
set @n1=@n1+1
end
return
end
select * from dbo.f_jj(10001,10005)
/*
a
-----------
10002
10003
10004
*/
@n1 varchar(10) ,@n2 varchar(10))
returns @s table (a varchar(10))
as
begin
while(@n1<@n2-1)
begin
insert @s values(@n1+1)
set @n1=@n1+1
end
return
end
select * from dbo.f_jj('10001','10005')
/*
a
-----------
10002
10003
10004
*/
select * from dbo.f_jj('abc','abe')?
declare @t1 table(id varchar(20))
insert @t1
select 'abc' union all
select 'abd' union all
select 'abe'select * from @t1
where id > 'abc' and id < 'abe'
--结果
id
abd
结果应该是:
abd
abe麦蒂的方法是针对可转化为整数的字符的
如‘10005’
select '10001' a union all select '10002' union all select '10003'union all select '10004')select * from cte
where a between '10001' and '10004'a
--------
10001
10002
10003
10004with cte as (
select 10001 a union all select 10002 union all select 10003 union all select 10004)select * from cte
where a between 10001 and 10004a
--------
10001
10002
10003
10004
declare @s varchar(10)
declare @e varchar(10)
set @s = 'abc'
set @e = 'abf'
select left(@s,len(@s) -1) + char(ascii(right(@s,1))+ number)
from master..spt_values
where type = 'P'
and ascii(right(@s,1)) + number between ascii(right(@s,1))+1 and ascii(right(@e,1))-1
/*
-----------
abd
abe(2 行受影响)
*/