set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_paging] (
@Tname varchar(255),/*表名*/
@kname varchar(255),/*主鍵名*/
@columns varchar(500),/*select的列名*/
@whereText varChar(500),/*查詢條件*/
@orderText varChar(100),/*排序條件*/
@startIndex int,/*取的數(shù)目開始值*/
@endIndex int/*取的數(shù)目的結(jié)束值*/
)
AS
BEGIN
SET NOCOUNT ON;
declare @sqlstring varchar(1000)
set rowcount @endIndex
DECLARE @tableid varchar(20)
DECLARE @idType varchar(20)
select @tableid=id from sysobjects where name=@Tname
select @idType=xtype from sysColumns where id=@tableid and LOWER(name)='id'
/*如果主鍵Id為varchar時(shí),則臨時(shí)表的nid為varchar,否則為int*/
if @idType='167'
begin
/*得到一張有順序Id的臨時(shí)表,用戶分頁(yè)*/
select @sqlstring = 'declare @indextable table(id int identity(1,1),nid varchar(50))
insert into @indextable(nid)
select '+@kname+' from '+@Tname+' where '+@whereText+' order by '+@orderText
+' select '+@columns+' from '+@Tname+' t, @indextable o where t.'+@kname+' =o.nid
and o.id between '+convert(varchar,@startIndex)
+' and '+convert(varchar,@endIndex) +' order by o.id'
end
else
begin
select @sqlstring = 'declare @indextable table(id int identity(1,1),nid int)
insert into @indextable(nid)
select '+@kname+' from '+@Tname+' where '+@whereText+' order by '+@orderText
+' select '+@columns+' from '+@Tname+' t, @indextable o where t.'+@kname+' =o.nid
and o.id between '+convert(varchar,@startIndex)
+' and '+convert(varchar,@endIndex) +' order by o.id'
end
exec(@sqlstring)
SET NOCOUNT OFF;
END
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_paging] (
@Tname varchar(255),/*表名*/
@kname varchar(255),/*主鍵名*/
@columns varchar(500),/*select的列名*/
@whereText varChar(500),/*查詢條件*/
@orderText varChar(100),/*排序條件*/
@startIndex int,/*取的數(shù)目開始值*/
@endIndex int/*取的數(shù)目的結(jié)束值*/
)
AS
BEGIN
SET NOCOUNT ON;
declare @sqlstring varchar(1000)
set rowcount @endIndex
DECLARE @tableid varchar(20)
DECLARE @idType varchar(20)
select @tableid=id from sysobjects where name=@Tname
select @idType=xtype from sysColumns where id=@tableid and LOWER(name)='id'
/*如果主鍵Id為varchar時(shí),則臨時(shí)表的nid為varchar,否則為int*/
if @idType='167'
begin
/*得到一張有順序Id的臨時(shí)表,用戶分頁(yè)*/
select @sqlstring = 'declare @indextable table(id int identity(1,1),nid varchar(50))
insert into @indextable(nid)
select '+@kname+' from '+@Tname+' where '+@whereText+' order by '+@orderText
+' select '+@columns+' from '+@Tname+' t, @indextable o where t.'+@kname+' =o.nid
and o.id between '+convert(varchar,@startIndex)
+' and '+convert(varchar,@endIndex) +' order by o.id'
end
else
begin
select @sqlstring = 'declare @indextable table(id int identity(1,1),nid int)
insert into @indextable(nid)
select '+@kname+' from '+@Tname+' where '+@whereText+' order by '+@orderText
+' select '+@columns+' from '+@Tname+' t, @indextable o where t.'+@kname+' =o.nid
and o.id between '+convert(varchar,@startIndex)
+' and '+convert(varchar,@endIndex) +' order by o.id'
end
exec(@sqlstring)
SET NOCOUNT OFF;
END
浙公網(wǎng)安備 33010602011771號(hào)