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

万能的分页sql(转)

CREATE proc page
@RecordCount int output,
@QueryStr nvarchar(100)='table1',--表名、视图名、查询语句
@PageSize int=20, --每页的大小(行数)
@PageCurrent int=2, --要显示的页 从0开始
@FdShow nvarchar (1000)='*', --要显示的字段列表
@IdentityStr nvarchar (100)='id', --主键
@WhereStr nvarchar (200)='1=1',
@FdOrder nvarchar(100)='desc' --排序 只能取desc或者asc
as
declare
@sql nvarchar(2000)
set @sql = ''
if @WhereStr = ''
set @WhereStr = '1=1'
if @PageCurrent = 0 begin
set @sql = 'select top ' + cast(@PageSize as nvarchar(3)) + ' ' + @FdShow + ' from ' + @QueryStr + ' where ' + @WhereStr + ' order by ' + @IdentityStr + ' ' + @FdOrder
end
else begin
if upper(@FdOrder) = 'DESC' begin
set @sql = 'select top ' + cast(@PageSize as nvarchar(3)) + ' ' + @FdShow + ' from ' + @QueryStr + ' where ' + @WhereStr + ' and ' + @IdentityStr + '< ( select min(' + @IdentityStr + ') from (select top ' + cast(@PageSize*@PageCurrent as nvarchar(10)) + ' ' + @IdentityStr + ' from ' + @QueryStr + ' where ' + @WhereStr + ' order by ' + @IdentityStr + ' desc) as t) order by ' + @IdentityStr + ' desc'
end
else begin
set @sql = 'select top ' + cast(@PageSize as nvarchar(3)) + ' ' + @FdShow + ' from ' + @QueryStr + ' where ' + @WhereStr + ' and ' + @IdentityStr + '> ( select max(' + @IdentityStr + ') from (select top ' + cast(@PageSize*@PageCurrent as nvarchar(10)) + ' ' + @IdentityStr + ' from ' + @QueryStr + ' where ' + @WhereStr + ' order by ' + @IdentityStr + ' asc) as t) order by ' + @IdentityStr + ' asc'
end
end
--print @sql
execute(@sql)
if(@RecordCount is null or @RecordCount<=0)begin
declare @tsql nvarchar(200)
set @tsql=N'select @RecordCount = count(*) from ' + @QueryStr + ' where ' + @WhereStr
exec sp_executesql @tsql,N'@RecordCount int output',@RecordCount output
select @Recordcount
end
GO


相关文档:

MS SQL 2005 32/64位下载

MS SQL 2005 32/64位下载
thunder://QUFmdHA6Ly9TaGFyZToxNjQzQHd3dy5zb293ZWIubmV0L1NoYXJlL1NlcnZlci9NaWNyb3NvZnQlMjBTUUwlMjBTZXJ2ZXIlMjAyMDA1L1NRTC4yMDA1LmFsbC5jaHMuaXNvWlo=
Microsoft SQL Server 2005 CHN 32位 CD1
ed2k://|file|%5B%E5%BE%AE%E8%BD%AFSQL%E6%9C%8D%E5%8A%A1%E5%99%A82005%E7%AE%80%E4%BD%93% ......

【小小问题集锦13之 关于分组加顺序号的SQL写法】


/*
原表:  
thid      other  
a              1  
a              1  
b              0  
b              0  
......

三种sql分页方法

表中主键必须为标识列,[ID] int IDENTITY (1,1)
1.分页方案一:(利用Not In和SELECT TOP分页)
语句形式: 
SELECT TOP 页记录数量 *
from 表名
WHERE (ID NOT IN
  (SELECT TOP (每页行数*(页数-1)) ID
  from 表名
  ORDER BY ID))
  ORDER BY ID
//自己还可以加上一些查询 ......

完全卸载SQL Server 2005

SQL Server 2005(适用于2000)的卸载是一个非常头疼的问题。我曾经尝试过直接使用【添加或删除程序】工具卸载、清除安装目录、删除注册表内容等等各种方式综合卸载,勉强成功。现在终于找到了一个事半功倍的方法,多次尝试,未有失败,具体如下:
1.下载卸载工具,有两种:
第一种是微软官方提供的工具(msicuu2.exe)
http ......

My PL/SQL practice 8/2/10

SQLPlus  :http://www.orafaq.com/wiki/SQL*Plus_FAQ
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm
1. Transfer values from a sql scripts:
   CNT=`sqlplus -s username/password1@dbname @getUVQuery_NULLCNT`;
 
   Note : Remeber to use o ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号