Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 char to PLU_NUM(float)

Author  Topic 

skybvi
Posting Yak Master

193 Posts

Posted - 2011-08-26 : 10:34:45
Hi,
I have 2 tables to join on a common field(column) having char and PLU_NUM(float) values..They have values like ..298748372690 (all numbers)
I cant edit the table with PLU_NUM(float) but can change the other table having values in char.
So i need to change all char values to PLU_NUM(float)..
How is it possible.

Thanks.

Regards,
Sushant
DBA
West Indies

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-08-26 : 10:54:06
Joining on Floating point numbers is inherently dangerous because they are not precise so I'm a bit wary to offer advice.

Can you give us the table definitions and some sample data.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-26 : 10:54:40
how can you convert the nonnumeric data to float?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

skybvi
Posting Yak Master

193 Posts

Posted - 2011-08-26 : 11:06:06
@transact charlie..

One table has UPC(char)(common column) values as :-

780295006947
750105920637
1500000701
1500000802
1500000702
Other table has ITM_ID(PLU_NUM(float))(common column) values as :-

1150900411
1150900422
1150900462
1150900708
1150900713

I want to join both tables on common values..
BUT getting error cannot convert varchar to float.



Regards,
Sushant
DBA
West Indies
Go to Top of Page

skybvi
Posting Yak Master

193 Posts

Posted - 2011-08-26 : 12:30:02
Hi,
I changed the data types successfully..
I used

SELECT CAST(mycolname AS float) FROM tablename
SELECT CONVERT(FLOAT, mycolname) FROM tablename

After running above statments,
I still got same error "it cannot convert varchar to float" but that it stopped after showing some results
so i saw that the next column values wich it cannot do were like '344723-547'

so i removed '-' from the values
and then again i ran CAST and CONVERT and
then when i went into table name right click design, i would change it to float. :)
Thanks


Regards,
Sushant
DBA
West Indies
Go to Top of Page
   

- Advertisement -