Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 page count

Author  Topic 

craigmacca
Posting Yak Master

142 Posts

Posted - 2008-09-03 : 08:57:32
Hi i need to do the following

SELECT count(*) / 20 as [PageCount]
FROM ShoppingBasket


but the problem i have is if the page count is 43 then i need the [PageCount] to be 3 not 2 as i am getting now

just not sure how to do this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-03 : 08:59:25
SELECT ceiling(count(*) / 20.0) as [PageCount]
FROM ShoppingBasket



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-09-03 : 09:00:40
SELECT CEILING(Count(*)*1.0/20)

Jim
Go to Top of Page

craigmacca
Posting Yak Master

142 Posts

Posted - 2008-09-03 : 09:36:58
ok thanks, this is a stored proc and i have some asp code to retreive the data which is

int count = (int)db.ExecuteScalar(cmd);
return count;
}

this is now erroring when using
SELECT ceiling(count(*) / 20.0) as [PageCount]
FROM ShoppingBasket

any ideas?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-03 : 09:53:03
SELECT cast(ceiling(count(*) / 20.0) as int) as [PageCount]
FROM ShoppingBasket


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-04 : 05:09:11
And here is why you need 20.0 instead of 20
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -