Problem with inserting float in SQL Server

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
tanay.sd
Participant
Posts: 10
Joined: Mon Apr 26, 2010 4:56 pm
Location: Portland

Problem with inserting float in SQL Server

Post 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.
Tanay
greggknight
Premium Member
Premium Member
Posts: 120
Joined: Thu Oct 28, 2004 4:24 pm

Post 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

:?: :?:
"Don't let the bull between you and the fence"

Thanks
Gregg J Knight

"Never Never Never Quit"
Winston Churchill
tanay.sd
Participant
Posts: 10
Joined: Mon Apr 26, 2010 4:56 pm
Location: Portland

Post 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.
Tanay
Post Reply