Page 1 of 1

Problem with inserting float in SQL Server

Posted: Wed May 11, 2011 8:11 am
by tanay.sd
Hi,

I have a job which reads from a sequential file, trims data in a transformer, and then loads into a table (SQL Server 2005)

There are some columns in the target table which are designated as float and are displaying curious behaviour.

Source Value -- 000004876274.70
Target Value -- 4876274.5

Source Value -- 0006.0300
Target Value -- 6.03000020980835

This behaviour is not restricted to a single column, and till now I have tried following approaches to correct this anomaly,
  • read data as varchar and then convert it to decimal and then to float and then insert it.
    read it as float and insert it as float
none of the above approaches have worked so far, any insight into why this is happening and a possible solution will be greatly appreciated.

Posted: Wed May 11, 2011 4:19 pm
by greggknight
Are you referring to the right side of the decimal?

I did this and got that
create table gregg(
myfloat float,
myfloat2 float
)

Insert into gregg
values(
000004876274.70,
0006.0300)

select * from gregg
myfloat myfloat2
4876274.7 6.03

I defined both numbers as char(putting quotes around them) same result

:?: :?:

Posted: Wed May 11, 2011 5:30 pm
by tanay.sd
Hi Gregg, Thanks for your reply, eventually that's what i did too, i read it as varchar and inserted it as varchar.