SQL Server 2008 query analyzer adds trailing 0 in decimal field

When I try to execute below query analyzer in two different servers i'm getting two different results, What kind of setting could be different

Server 1
select myfield from tmytable
25

Server 2
select myfield from tmytable
25.0000000
Bharat GuruAsked:
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.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
First place I'd look is the data type of column myfield in table tmytable in each server.
Guessing Server 1 it's an int or character, and Server 2 it's something like numeric(9,7)
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
May the two fields have different data types? Did you check that?
0
Bharat GuruAuthor Commented:
both server are accessing data from same server same table same query
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Can you post the exact query with some sample data?
0
Bharat GuruAuthor Commented:
Data type is is [decimal](38, 18)
when I insert the value ast 15.1   in table it stores as 15.100000000000000000
how can I declare the field type which can stores max 18 decimal but when I add 15.1 is should store the actual value without leading 0s
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Just to clarify terms...
leading 0's = 00000000000000000000042.478
trailing 0's = 15.100000000000000000
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>how can I declare the field type which can stores max 18 decimal but when I add 15.1 is should store the actual value without leading 0s
No can do.  If a numeric data type is defined with a scale of 18 decimal places, then it's going to store any values with .00000 00000 00000 000 zeros.  There is no way to override this and say 'Just store it as .1'.

So ... define for us why you wish to alter storing the number, as opposed to just alter how it's displayed.
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
Vitor MontalvãoMSSQL Senior EngineerCommented:
One thing is how your data is stored and you can't do nothing with that unless you change the data type or precision for decimal fields.
Another thing is how you retrieve the data and for that you need to use the CAST or CONVERT function to achieve the format you want.
0
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
Microsoft SQL Server

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.