简单的 sql分页存储过程
【1】
create procedure proc_pager1
( @pageIndex int, -- 要选择第X页的数据
@pageSize int -- 每页显示记录数
)
AS
BEGIN
declare @sqlStr varchar(500)
set @sqlStr='select top '+convert(varchar(10),@pageSize)+
' * from orders where orderid not in(select top '+
convert(varchar(20),(@pageIndex-1)*@pageSize)+
' orderid from orders) order by orderid'
exec (@sqlStr)
END
【2】
create procedure proc_pager
( @startIndex int,--开始记录数
@endIndex int --结束记录数
)
as
begin
declare @indextable table(id int identity(1,1),nid int)
insert into @indextable(nid) select orderid from orders order by orderid desc
select *
from orders o
inner join @indextable i
on o.orderid=i.nid
where i.id between @startIndex and @endIndex
order by i.id
end
【3】适用于sql2005
create procedure proc_pager2
( @startIndex int,--开始记录数
@endIndex int --结束记录数
)
as
begin
WITH temptbl AS
(SELECT ROW_NUMBER() OVER (ORDER BY orderid DESC) AS Row, *from orders)
SELECT * from temptbl
where row between @startIndex and @endIndex
order by row
end
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
--A. 从存储在非类型化的 xml 变量中的文档中删除节点
DECLARE @myDoc xml
SET @myDoc = '<?Instructions for=TheWC.exe ?>
<Root>
<!-- instructions for the 1st work center -->
<Location LocationID="10" LaborHours="1.1" MachineHours=".2" >
Some text 1
<st ......
我使用delphi也不是很长时间,由于经常要用到SQL语句,总结了一些Delphi中使用SQL语句要注意的事项,归纳起来主要有一下几条:
一、空格不要漏:
我们经常要拼装SQL语句,特别是where条件句,在各个语句中别忘了头尾加上空格。因为在一个语句中我们会注意用空格分开关键字但是往往忘了头尾的空格。例如:
sSQL=' select ......
SQL Server 2005 不允许远程连接解决方法
刚刚安装的数据库系统,按照默认安装的话,很可能在进行远程连接时报错,通常是错误:"在连接到 SQL Server 2005 时,
在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。
(provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) "搜M ......
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
inner join(等值连接) 只返回两个表中联结字段相等的行
举例如下:
--------------------------------------------
表A记录如下:
aID aNum
1 a ......