Showing posts with label int. Show all posts
Showing posts with label int. Show all posts

Monday, March 12, 2012

Paging problems

I am using a stored procedure to page some objects
The procedure looks like this:

CREATE PROCEDURE sw20aut.sw20_Kon
( @.sid_nr INT, @.sid_stl INT = 35, @.kid int )
AS BEGIN
SET NOCOUNT ON
DECLARE
@.rader INT, @.sid_antal INT, @.ubound int, @.lbound int

SELECT
@.rader = COUNT(*),
@.sid_antal = COUNT(*) / @.sid_stl
FROM
sw20aut.sw_kontakter WITH (NOLOCK)
WHERE
kund_id = @.kid AND del = '0'

IF @.rader % @.sid_stl != 0 SET @.sid_antal = @.sid_antal + 1
IF @.sid_nr < 1 SET @.sid_nr = 1
IF @.sid_nr > @.sid_antal SET @.sid_nr = @.sid_antal

SET @.ubound = @.sid_stl * @.sid_nr
IF(@.sid_antal > 0) SET @.lbound = @.ubound - (@.sid_stl - 1)
ELSE SET @.lbound = 0

SELECT
CurrentPage = @.sid_nr,
TotalPages = @.sid_antal,
TotalRows = @.rader

DECLARE @.ename VARCHAR(64), @.fname VARCHAR(64), @.konid VARCHAR(64)
SET ROWCOUNT @.lbound
SELECT @.ename = enamn, @.fname = fnamn, @.konid = kon_id FROM sw20aut.sw_kontakter WITH (NOLOCK)
WHERE kund_id = @.kid AND del = '0'
ORDER BY enamn, fnamn, kon_id
SET ROWCOUNT @.sid_stl
SELECT kon_id, enamn, fnamn FROM sw20aut.sw_kontakter WITH (NOLOCK)
WHERE enamn + fnamn + '~' + CAST(kon_id as VARCHAR(64)) >= @.ename + @.fname + '~' + @.konid AND (kund_id = @.kid AND del = '0')
ORDER BY enamn, fnamn, kon_id
SELECT startid = @.konid
SET ROWCOUNT 0
END

The big problem is that i need to display objet with the same name. In my book the best identifier is the PK and therefor i have sorted as above by ordering after LastName, FirstName, ContactId

After som thinking ive reached the conclusion that this dont work if the idnumbers isnt of the same length. as long as they are(for example two people named John Smith, one with id = '23' and one with id = '87' it works. If there ids would have been '23' and '1203' it will not work correctly) of the same length it works fine.

What im wondering is if anyone have a good solution to this? Only thing i can think of is filling all idnumbers with zeros to equal length. Dont know how and if this will affect performance though. Anyone has a practical solution to this?

Sorry I'm not clear what you want to do in the stored procedure, it may help to understand your issue if you can post some sample data and expecting result returned by the stored procedure. For paging result sets, if you're using SQL2005/Express you can try the new?Ranking functions

Friday, March 9, 2012

paging

please let me know the steps to set
=Int((RowNumber(Nothing)-1)/2)
expression for pagebreak in rdl file.On Apr 18, 7:34 am, abhi <a...@.discussions.microsoft.com> wrote:
> please let me know the steps to set
> =Int((RowNumber(Nothing)-1)/2)
> expression for pagebreak in rdl file.
Something like this should work.
1. Right click the list/table/matrix control and select 'Properties'
from the drop-down list.
2. Select the 'Edit details group...' button.
3. On the 'General' tab, below 'Group on:' and 'Expression' type in
something similar to the following:
=Ceiling(RowNumber(Nothing)/25)
Where, in this example, 25 is the number of rows per page. Then select
'Page break at end' in the Properties of the list/table/matrix
control. Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant

Saturday, February 25, 2012

page splits

Say you have a table as such
create table test
(col1 int identity(1,1) primary key,
col2 varchar(10),
col3 varchar(10))
and now you pound this table with heavy inserts from multiple clients
Can it cause page splits ? It would appear that its inserting in order in
col1 and that pages will be ordered and written sequentially.. If it does
cause page splits, can you explain how ? And also will changing col1 to
nonclustered help ?
ThanksIt should not create page splits on inserts alone but if you update the
varchars later to a value larger than the original it can cause a split.
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Hassan" <hassan@.hotmail.com> wrote in message
news:%23B8bqUlFIHA.4308@.TK2MSFTNGP06.phx.gbl...
> Say you have a table as such
> create table test
> (col1 int identity(1,1) primary key,
> col2 varchar(10),
> col3 varchar(10))
> and now you pound this table with heavy inserts from multiple clients
> Can it cause page splits ? It would appear that its inserting in order in
> col1 and that pages will be ordered and written sequentially.. If it does
> cause page splits, can you explain how ? And also will changing col1 to
> nonclustered help ?
> Thanks
>