Link to home
Start Free TrialLog in
Avatar of Bharat Guru
Bharat Guru

asked on

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
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

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)
May the two fields have different data types? Did you check that?
Avatar of Bharat Guru
Bharat Guru

ASKER

both server are accessing data from same server same table same query
Can you post the exact query with some sample data?
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
Just to clarify terms...
leading 0's = 00000000000000000000042.478
trailing 0's = 15.100000000000000000
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.