易截截图软件、单文件、免安装、纯绿色、仅160KB

简单的 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


相关文档:

[转]生成无级树(sql函数)

--处理示例
--示例数据
create table tb(ID int,Name varchar(10),ParentID int)
insert tb select 1,'AAAA'    ,0
union all select 2,'BBBB'    ,0
union all select 3,'CCCC'    ,0
union all select 4,'AAAA-1'  ,1
union all select 5,'AAAA-2'  ,1
u ......

C++通过ADO连接ACCESS(或者SQL Server)数据库例子

#include "iostream.h"
#include "stdio.h"
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
int main(int argc, char* argv[])
{
   ::CoInitialize(NULL);
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
tr ......

pl/sql报ora 12154:TNS:无法解析指定的连接符问题

解决方法一
在oraDb10g_home->配置和移植工具->net Manager
      在本地中新建一个服务命名
这个网络服务名就是登陆时的数据库名
完成这些操作后,选择菜单中文件->保存网络配置就ok了。
解决方法二
打开安装目录下服务器端的tnsnames.ora,比如我的完整目录是E:\oracle\product\ ......

sql 加密

use Tempdb
go
if object_ID ( 'fn_ACITEncryption' ) is not null
drop function fn_ACITEncryption
go
create function fn_ACITEncryption
(
@Str nvarchar ( 4000), -- 加密的字符串
@Flag bit = 1, --1 、加密 0 、解密
@Key nvarchar ( 50) -- 密文
)
returns nvarchar ( 4000) ......

SQL 每个分类各取2条数据

create table tb (ptoid int,proclassid int,proname varchar(10))
insert tb
select 1,1,'衣服1'
union all
select 2,2,'衣服2'
union all
select 3,3,'衣服3'
union all
select 4,3,'衣服4'
union all
select 5,2,'衣服5'
union all
select 6,2,'衣服6'
union all
select 7,2,'衣服7'
union all
select 8 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号