--1.直接查询
select * from 表 where [index] between 3 and 5
select * from 表 where [index] between 3 and 5
解决方案 »
- SQL SERVER 2005重装问题
- 在网上见到一段代码“用T-SQL获得当前连接客户端IP和机器名”,可是提示错误,是何原因?
- 大家帮我看看这个存储过程,检测没错,但运行结果就是不正确,怪,请各位指点.
- 找高手探讨sqlserver事件信息采集
- 求一条分组查询语句,谢谢各位。
- 关于SQL语句优化的问题
- 数状结构转换问题!
- 急!!!!!!!!!!!!!!!!!!!!!!!!
- sqlserver新手提问,有没有能调试存储过程的工具像oracle的pldev那样的
- 【求助】在没有装mysql数据库的linux上如何远程备份服务器上的。sql文件到本地?
- 数据库备份问题!马上给分!
- 關於1433端口問題.
create proc p_qry
@begin int,
@end int
as
select * from 表 where [index] between @begin and @end
go--调用
exec p_qry
exec p_qry 3,5--3.写成函数
create function f_qry(
@begin int,
@end int
)returns tables
as
return(select * from 表 where [index] between @begin and @end)
go--调用
select * from f_qry(3,5)
as
set nocount on
declare @sql varchar(8000)set @sql='select index ,name ,sex from tb where index between '+@a+' and '+ @b+''
exec(@sql)go
是游标吗?代码中怎么来调用存储过程
exec p_qry 3,5
把它運行起來
returns tables
提示无法找到tables的数据类型
请问是什么原因啊,谢谢
returns tables改为
returns table
create function f_qry(
@begin int,
@end int
)returns table
as
return(
select * from 表 a
where (select count(*) from 表 where [index]<=a.[index])
between @begin and @end)
go--调用
select * from f_qry(3,5)
你排序后是不是按照index从小到大排列的?
如果不是的话,可以这样查:
--m-n行的数据
select top n-m+1 * from 表 where index not in(select top m-1 index from 表)
在临时表里增加自增列字段[id]
取临时表里[id]3-5的数据
alter table TempTable1 add [id] int identity如果显示[id]也没关系的话
select * from TempTable1 where [id] between 3 and 5如果不要显示[id]
select a.字段A,a.字段B....from TempTable1 a where a.[id] between 3 and 5
这可以在存储过程中如何并在一起啊
alter table TempTable1 add [id] int identity如果显示[id]也没关系的话
select * from TempTable1 where [id] between 3 and 5如果不要显示[id]
select a.字段A,a.字段B....from TempTable1 a where a.[id] between 3 and 5drop table TempTable1
@begin int,
@end int
)returns table
as
select * into TempTable1 from 表 order by [index]
alter table TempTable1 add [id] int identity
return(select * from TempTable1 where [id] between 3 and 5) --如果显示[id]也没关系的话
drop table TempTable1
go--调用
select * from f_qry(3,5)
@begin int,
@end int
)returns table
as
select * into TempTable1 from 表 order by [index]
alter table TempTable1 add [id] int identity
return(select a.字段A,a.字段B....from TempTable1 a where a.[id] between 3 and 5) --如果不要显示[id]
drop table TempTable1
go--调用
select * from f_qry(3,5)
create table tb([index] int,name varchar(10),sex varchar(10))
insert tb select 1,'jj','F'
union all select 3,'dd','M'
union all select 2,'ll','F'
union all select 4,'rr','F'
union all select 8,'aa','M'
union all select 6,'xx','M'
union all select 7,'pp','F'
union all select 5,'zz','F'
go--原来写的函数,按index顺序
create function f_qry(
@begin int,
@end int
)returns table
as
return(
select * from tb a
where (select count(*) from tb where [index]<=a.[index])
between @begin and @end)
go--调用
select * from f_qry(3,5)/*--测试结果index name sex
----------- ---------- ----------
3 dd M
4 rr F
5 zz F(所影响的行数为 3 行)
--*/
go--查询的函数2,按表中的记录顺序
create function f_qry1(
@begin int,
@end int
)returns @re table([index] int,name varchar(10),sex varchar(10))
as
begin
declare @t table(id int identity,[index] int,name varchar(10),sex varchar(10))
insert @t select * from tb
insert @re select [index],name,sex from @t
where id between @begin and @end
return
end
go--调用
select * from f_qry1(3,5)/*--测试结果index name sex
----------- ---------- ----------
2 ll F
4 rr F
8 aa M(所影响的行数为 3 行)
--*/
go--删除测试
drop table tb
drop function f_qry,f_qry1