SQL 명령문레코드

2314 단어
1. 페이지 저장 프로세스의 생성과 호출.
-------------        ——————————
if exists(select * from sysobjects where name='pading') --      pading    
drop procedure pading --     
go
create procedure pading		--      pading
							--    
	@currentPage int=0,		--    ,    0,    
	@pageSize int=5,		--       ,    5
	@countPage int output,	--    ,     
	@countRows int output	--    ,      
as
select top (@pageSize) * from temp	--    @pageSize        
where id not in (select top (@pageSize*@currentPage) id from temp ) 
order by id
set @countRows=(select count(*) from temp)	--  。          
set @countPage=@countRows/@pageSize	--  。        
if @countRows%@pageSize<>0	--  :               0
set @countPage=@countPage+1 --  +1
---------------end------------------------------------------------------------------------

---------------        -----------
declare @countpage int,@countrows int
exec pading 0,5,@countpage output,@countrows output
select @countpage,@countrows
---------------end------------------------
------------------------------        (  sql  )------------------------------------
--    :2011-08-26
--  :qingyun1029
if exists (select * from sysobjects where name='splitpage')
drop procedure splitpage
go
create procedure splitpage	
	@pageSize int=10,
	@currentPage int =0,
	@countRecord int output,
	@countPage int output
as
declare @sql nvarchar(1000)
--  :  sql   ,             +   ,   cast  ,  :
set @sql=N'select top '+cast(@pageSize as nvarchar(10))
		 +' * from temp where id not in (select top '
		 +cast((@pageSize*@currentPage) as nvarchar(10))+' id from temp)'
exec sp_executesql @sql
set @countRecord=(select count(*) from temp)
set @countPage=@countRecord/@pageSize
if(@countRecord%@pageSize<>0)
set @countPage=@countPage+1
------------------------------      ------------------------------------
declare @cRecord int, @cPage int
exec splitpage 500,2,@cRecord output,@cPage output
select @cRecord,@cPage
--------------------------------end-----------------------------------------------

2, sql에서 사용 순환, 테스트 데이터 삽입
declare @star int
set @star=0
while @star<100000
begin
	insert into temp
	values('qingyun',24)
	set @star=@star+1
end

좋은 웹페이지 즐겨찾기