Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql decimal question 2

Status
Not open for further replies.

03Explorer

Technical User
Sep 13, 2005
304
US
problem is I want to perform a simple calculation in SQL and have the result returned with 10ths decimal place populated... no more or less than that.

SELECT procedure, dob, (procedure - dob)/365 as age
FROM table

I find if I leave the 365 as whole number my returned value is whole value. if I put just a decimal place after 365 = '365.' then it returns 4 decimal places.

How can I return with 2 decimal places?
 
try this:

SELECT procedure, dob, (procedure - dob)/365.00 as age
FROM table

-DNG
 
.00 or .0 or even just . gives me the same many decimal places response.

XplorR
 
how about this:

SELECT procedure, dob, Cast((procedure - dob)/365 as decimal(3,2)) as age
FROM table

-DNG

 
I get an error message from sybase that says "Select error: SQLSTATE = 22003 [Sybase][ODBC Driver][Adaptive Server Anywhere]value 50 out of range for destination" with an OK button.

I checked both Proc_date & dob for null's and there are none.
 
It may be a bit of a resource hog but try this

SELECT procedure, dob, cast(round(((procedure - dob)/365.),2) as decimal(6,2)) as age
FROM table
 
i suggested decimal(3,2) because i dont think anyone can live for an age which will be a 6 digit number...

-DNG
 
DNG - my bad. I somehow managed to miss your post, didn't mean to repeat it. I was playing with a financial export with a (6,2) when I saw this thread and missed that change.
 
Apologies for the delayed response. It works just as expected. Thank you for your help.
 
I ended up using:

Code:
SELECT procedure, dob, cast(round(((procedure - dob)/365.),2) as decimal(3,2)) as age 
FROM table

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top