| Author |
Topic |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2005-08-19 : 12:10:54
|
| hm it will be like thatselect count(*)/10 from Customers //that will get the number of pagesthenon vs.net section i will add the numbers that resulted from here to a dropdownlist. for example from 1 to 5 it will add page numbers (for totaly 50 record)So when you select the 3. page iwant to get the 3rd 10 records. Is there a way like that? When i select the 3. page. itwill request 20th,21th.....30th records.can it be??or is there another waY?MS BLESS US |
|
|
VladRUS.ca
Starting Member
23 Posts |
Posted - 2005-08-19 : 13:02:50
|
| Hi bilencekic,Try this code:===============================use Northwindgo-- select * from Customers order by CustomerIDdeclare @Handle int, @page int, @page_size int, @start_row_num int, @TotalRows int, @TotalPages intset @page_size = 10exec sp_cursoropen @Handle OUT, 'select * from Customers order by CustomerID', 1, 1, @TotalRows outset @TotalPages = ceiling(@TotalRows * 1./ @page_size)raiserror('TotalRows = %d, TotalPages by %d = %d', 0, 1, @TotalRows, @page_size, @TotalPages)-- Page 3select @page = 3, @start_row_num = (@page-1) * @page_size + 1exec sp_cursorfetch @Handle,16, @start_row_num, @page_size-- Page 1select @page = 1, @start_row_num = (@page-1) * @page_size + 1exec sp_cursorfetch @Handle,16, @start_row_num, @page_size-- Page 5select @page = 5, @start_row_num = (@page-1) * @page_size + 1exec sp_cursorfetch @Handle,16, @start_row_num, @page_size-- close cursorexec sp_cursorclose @Handlego |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2005-08-19 : 13:12:46
|
| wow :D it workedi will make sp version and that is nice really nice :)thx man thx very much ms bless you :P you are the king thxMS BLESS US |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-03-28 : 06:07:18
|
| ALTER PROCEDURE bp_UrunleriGetirSayfala-- select * from Customers order by CustomerID@altkategoriID intasdeclare @Handle int, @page int, @page_size int, @start_row_num int, @TotalRows int, @TotalPages intset @page_size = 10exec sp_cursoropen @Handle OUT, '(select * from Urunler where AltKategoriID = @altkategoriID)', 1, 1, @TotalRows outset @TotalPages = ceiling(@TotalRows * 1./ @page_size)raiserror('TotalRows = %d, TotalPages by %d = %d', 0, 1, @TotalRows, @page_size, @TotalPages)-- Page 3select @page = 1, @start_row_num = (@page-1) * @page_size + 1exec sp_cursorfetch @Handle,16, @start_row_num, @page_size-- close cursorexec sp_cursorclose @Handle---i cant use a variable in the query why ?Server: Msg 137, Level 15, State 2, Line 4Must declare the variable '@altkategoriID'.is there any alternate for a performanceable paging ?i read some articles but queries are too long and complexMS BLESS US |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-03-28 : 09:13:21
|
| set @a = 11 -- start at row 200set @b = 20-- end at row 250normally b-a+1 = 10 rows must return rigt?but 3 row returnedbut when i set it 1 and 10 10 rows returns normallybut when i set it9-102 rows returns but wrong results returns (first and second rows returns but i want 9th and 10 th rows to return )at 1-10result : 66 -1- ATI RADEON 9800 PRO67 -1- TI 420068 -1- 6800 PRO69 -1- GF 6800 PRO70 -1- 680071 -1- 6800s72 -1- 6800ss73 -1- 6800pro75 -1- 660076 -1- 6600swhen it is 9-10 resukt is :66 -1- ATI RADEON 9800 PRO67 -1- TI 4200but when 9-10 result must be 75 -1- 660076 -1- 6600sright????????so why rowcounts are right but results are wrong ? MS BLESS US |
 |
|
|
majkinetor
Yak Posting Veteran
55 Posts |
Posted - 2006-03-28 : 09:17:59
|
| It is bad that SQL Server doesn't keep some internal command similar to TOP like STARTING FROM that will do the trick together with TOP the best way like:select TOP 100 STARTING FROM 1000 ....Anyway, this is the best link I found for paging. You have 10 techiniques to do this, so U can choose your performance.http://www.aspfaq.com/show.asp?id=2120www.r-moth.com |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-03-28 : 09:21:15
|
| hm thx i am checking now.but isnt there a command for getrows between 10 and 20 or like this ?ID column is Identityso they change like12589i dont want to do it with datagridi wish i fint it on the linkthxMS BLESS US |
 |
|
|
majkinetor
Yak Posting Veteran
55 Posts |
Posted - 2006-03-28 : 09:29:05
|
| yes if you have ID.... but what if you don't ?I got across samples where ID is either not present or it is not in the integer form. Of course you can always create temporary table with identity column but that is not quite the best answer for this topic. Or it can be, depending on your problem>>i dont want to do it with datagrid>>i wish i fint it on the linkI find the best thing for this to be Repeater control. Since this is beyound the scope of this forum I am not going to elaborate this here, switch to ASP.NET forum. Just keep in mind that DataGrid is for qucik job and with Repeater you can customize things EXACTLY the way you want.www.r-moth.com |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-03-28 : 09:32:42
|
| when using temp tablei think you have to select al table to correct the ID number like 1,2,3,4,5,6,7yes with this you can pagebut dont you have to select all table ?MS BLESS US |
 |
|
|
majkinetor
Yak Posting Veteran
55 Posts |
Posted - 2006-03-28 : 09:34:09
|
| You don't need to correct numbers, just remember last one so you can useselect TOP X....WHERE ID > last_idwww.r-moth.com |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-03-28 : 09:39:29
|
| i have an idea ehehehi will have a column named pagenumberand it will store the row is belong to which page.when an insert runs select count(PageNumber) where PageNumber = (Select PageNumber from Table where ProductID = @@IDENTITY - 1)this query will check the laast products pagenumbersoif the count is 10 for the latest product new pagenumber will be insertedif count(pagenumber) is less then 10old pagenumber will be insertedso when i tr to queryi will just writeselect ....innerjoins etc etc.... from table where PageNumber = @variableehehe yes this will worki can betthis will workkkkkwhat do u think ?MS BLESS US |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-03-28 : 09:52:33
|
Does this help?  --datadeclare @t table (id int)insert @t select 1union all select 2union all select 5union all select 8union all select 9union all select 11union all select 12union all select 13union all select 14union all select 18union all select 19union all select 22union all select 23union all select 24union all select 25union all select 26union all select 28--inputsdeclare @pageSize intdeclare @pageNumber intset @pageSize = 5set @pageNumber = 2--calculation - number of pagesselect (count(*) - 1) / @pageSize + 1 as NumberOfPages from @t--calculation - page valuesdeclare @rowsToIgnore intdeclare @id intif @pageNumber > 1begin set @rowsToIgnore = @pageSize * (@pageNumber - 1) set rowcount @rowsToIgnore select @id = id from @t order by idendset rowcount @pageSizeselect id from @t where id > isnull(@id, 0) order by idset rowcount 0 Ryan Randallwww.monsoonmalabar.comIdeas are easy. Choosing between them is the hard part. |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-03-28 : 11:43:52
|
| grrrrrrrrrrrreeeeeeeeeeeeeeeAAAAAAAAAAAAATthx manMS BLESS US |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-03-28 : 16:44:30
|
| my first procedures read on sql profiler : 364 cpu:10 and 0 duration:0,10,40 (paging is made by datagrid )second is the query which is writen above by ryan , read on profiler is : 716 cpu:10 and 0 duration: 0,10,20 (paging on sql)total number of records : 120so is reading so much important ? which one must i choose ? i tink second one will be better because there wont work any datagrid functions and other stuffs that will slow down the reponse time of webpage.edit:i made some text and the ryans method requess 5-6 pages/sec on performance monitorbut mine requests 90-100 page/secryans respond a bit late but it is okay i think it depends on server so performance will be better than before.thxMS BLESS US |
 |
|
|
|