Sybase arithmetic overflow with run script to check database data and log usage

Hi,
I run a script below which always return error as below


SELECT "Database Name" = CONVERT(char(20), db_name(D.dbid)),
"Data Size" =
STR(SUM(CASE
WHEN U.segmap != 4 THEN U.size*(@@maxpagesize/1048576)
END
),10,1),
"Used Data" =
STR(SUM(CASE
WHEN U.segmap != 4
THEN size -
curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs)
END
)
*@@maxpagesize/1048576,10,1),
"Data Full%" =
STR(100 *
(1 - 1.0 *
SUM(CASE
WHEN U.segmap != 4
THEN curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs)
END
) / SUM(CASE
WHEN U.segmap != 4 THEN U.size
END
)
)
,9,1) + "%",
"Log Size" =
STR(SUM(CASE
WHEN U.segmap in (4, 7) THEN U.size*@@maxpagesize/1048576
END),10,1),
"Free Log" =
STR(lct_admin("logsegment_freepages",D.dbid)*@@maxpagesize/1048576,10,1),
"Log Full%" =
STR(100 * (1 - 1.0 * lct_admin("logsegment_freepages",D.dbid)
/ SUM(CASE WHEN U.segmap in (4, 7) THEN U.size END)),8,1) + "%"
FROM master..sysdatabases D,
master..sysusages    U
WHERE U.dbid = D.dbid
AND (((D.dbid > 3) AND (D.dbid < 31513) OR D.dbid = 2)  AND (D.status != 256))
GROUP BY D.dbid
ORDER BY db_name(D.dbid)



Msg 3606, Level 16, State 4:
Server 'Sybase_test', Line 1:
Arithmetic overflow occurred.

motioneyeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe WoodhousePrincipal ConsultantCommented:
Think this is your problem:

     WHEN U.segmap != 4 THEN U.size*(@@maxpagesize/1048576)

Notice that every other time you do a size calculation, you don't have those parentheses. Try replacing it with:

     WHEN U.segmap != 4 THEN U.size*@@maxpagesize/1048576
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Sybase Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.