This topic is locked
[SOLVED]

 Converting pages to sheets

2/15/2011 10:17:22 AM
ASPRunnerPro General questions
G
goffj1 author

I have a print job log file where the number of pages for a job are recorded and whether it was a duplex job.
I want to calculate the number of sheets used but cannot simply divide by 2 as any job with an odd number of pages would be incorrect since you can't consume half of a sheet of papge.
In an MS-Access query the Int() function takes care of this but I am having trouble finding how to do this in SQL.
Any direction would be appreciated.
Here is code -
Select

dbo.JobLog.username

dbo.JobLog.Duplex

dbo.JobLog.TotalPages

IF dbo.JobLog.Duplex=-1 THEN -Int(-dbo.JobLog.TotalPages/2) as Sheets

ELSE dbo.JobLog.TotalPages as Sheets

END IF

From

dbo.JobLog

Sergey Kornilov admin 2/15/2011
G
goffj1 author 2/16/2011



Here is the link that can help:

http://www.google.com/search?q=sql+server+round+number



In trying to simplify the ROUND statement to see how it works, does .5 round down or up.
The following results in "incorrect syntax near 'dbo.'"
ROUND(dbo.JobLog.TotalPages/2,1) as Sheets
If I substitute brackets, quotes - single or double, for the parenthasis I still get the syntax error.

Sergey Kornilov admin 2/16/2011

Try ROUND(TotalPages/2,1) as Sheets

G
goffj1 author 2/17/2011



Here is the link that can help:

http://www.google.com/search?q=sql+server+round+number



I got it working by placing a comma after the last field name in the line just before the calculation.
The final line that seems to be working correctly is -
CASE WHEN dbo.JobLog.Duplex=1 THEN dbo.JobLog.TotalPages/2 ELSE ROUND(dbo.JobLog.TotalPages/2,1)+1 END AS Sheets
Thanks