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

Server 2
select myfield from tmytable
Bharat GuruAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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 Data DudeCommented:
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)
Vitor MontalvãoMSSQL Senior EngineerCommented:
May the two fields have different data types? Did you check that?
Bharat GuruAuthor Commented:
both server are accessing data from same server same table same query
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Vitor MontalvãoMSSQL Senior EngineerCommented:
Can you post the exact query with some sample data?
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
Jim HornMicrosoft SQL Server Data DudeCommented:
Just to clarify terms...
leading 0's = 00000000000000000000042.478
trailing 0's = 15.100000000000000000
Jim HornMicrosoft SQL Server Data DudeCommented:
>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.

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.
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.