473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to convert from ntext to float?

Hello,

I would like to convert a field from ntext field found in one database
table to float field found in another database table. The reason why I
want to do this is a long one.

I have tried the following and playing around with the following:

declare @valuePointer varbinary(16)

<Row cursor logic to initialize @valuePointer to be a pointer to the
source ntext field>

update TargetFloatTable set TargetFloatTable.TargetFloatValue =
CAST(CAST(@valuePointer AS nvarchar) AS float)
where TargetFloatTable.Id = @Id

but is not working for me.

Hoping someone out there can help.

Thanks,

Cally

Jul 23 '05 #1
5 18482
On 15 Mar 2005 13:35:22 -0800, Cally wrote:
update TargetFloatTable set TargetFloatTable.TargetFloatValue =
CAST(CAST(@valuePointer AS nvarchar) AS float)
where TargetFloatTable.Id = @Id


Try:

update TargetFloatTable set TargetFloatTable.TargetFloatValue =
CAST(CAST(@valuePointer AS nvarchar(255)) AS float)
where TargetFloatTable.Id = @Id
Jul 23 '05 #2
Cally (ze**********@hotmail.com) writes:
I would like to convert a field from ntext field found in one database
table to float field found in another database table. The reason why I
want to do this is a long one.

I have tried the following and playing around with the following:

declare @valuePointer varbinary(16)

<Row cursor logic to initialize @valuePointer to be a pointer to the
source ntext field>

update TargetFloatTable set TargetFloatTable.TargetFloatValue =
CAST(CAST(@valuePointer AS nvarchar) AS float)
where TargetFloatTable.Id = @Id

but is not working for me.


You are trying to convert the text pointer to float - that is not
very likely to succeed. Here is an example that works:

CREATE TABLE nt (a int, n ntext)
go
INSERT nt (a, n) values (1, '9.234E30')
go
select convert(float, convert(nvarchar, n)) from nt

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3
Yes, I was doing some funky things with text pointer that was not
going to work.

So based on your suggestion, I tried this:

update TargetTable set TargetTable.TargetFloatValue = (select
convert(float, convert(nvarchar, OtherTable.NTextValue)) from
OtherTable where OtherTable.ID = @id) where TargetTable.ID = @id

And I get the following error:

"Error converting data type nvarchar to float."

Which really surprises me because it is basically what you have
written and because the following works:

updatetext TargetTable TargetTable.NTextValue @ptrText 0 NULL
OtherTable.NTextValue @valuePointer

update TargetTable set TargetTable.TargetFloatValue = convert(float,
convert (nvarchar, TargetTable.NTextValue)) where TargetTable.ID =
@id

update TargetTable set TargetTable.NTextValue = NULL where
TargetTable.ID = @id

However, even though this appears to be working, I am using an
intermediate table field which I have to clear after I have converted
and move the value over and I do not want to execute 3 update queries
if I can only do one.

Your help is appreciated,

Cally
Erland Sommarskog <es****@sommarskog.se> wrote in message news:<Xn**********************@127.0.0.1>...
Cally (ze**********@hotmail.com) writes:
I would like to convert a field from ntext field found in one database
table to float field found in another database table. The reason why I
want to do this is a long one.

I have tried the following and playing around with the following:

declare @valuePointer varbinary(16)

<Row cursor logic to initialize @valuePointer to be a pointer to the
source ntext field>

update TargetFloatTable set TargetFloatTable.TargetFloatValue =
CAST(CAST(@valuePointer AS nvarchar) AS float)
where TargetFloatTable.Id = @Id

but is not working for me.


You are trying to convert the text pointer to float - that is not
very likely to succeed. Here is an example that works:

CREATE TABLE nt (a int, n ntext)
go
INSERT nt (a, n) values (1, '9.234E30')
go
select convert(float, convert(nvarchar, n)) from nt

Jul 23 '05 #4
Nevermind ... I am still testing but I think that I figured it out.

@valueText is nvarchar local variable that I populate from the
OtherTable.NTextValue in the fetch cursor

update TargetTable set TargetTable.TargetTableFloatValue =
convert(float, @valueText) where TargetTable.ID = @id

I realize that it is not ideal to do all of this converting and mixing
cursor-fetch-updatetext and regular updates. My problem of having 3
value fields (datetime, ntext, and float) that only one should be
updated based on DataType field seems to call for it.

Is there a better way to do this?

"Cally" <ze**********@hotmail.com> wrote in message news:<11*********************@o13g2000cwo.googlegr oups.com>...
Hello,

I would like to convert a field from ntext field found in one database
table to float field found in another database table. The reason why I
want to do this is a long one.

I have tried the following and playing around with the following:

declare @valuePointer varbinary(16)

<Row cursor logic to initialize @valuePointer to be a pointer to the
source ntext field>

update TargetFloatTable set TargetFloatTable.TargetFloatValue =
CAST(CAST(@valuePointer AS nvarchar) AS float)
where TargetFloatTable.Id = @Id

but is not working for me.

Hoping someone out there can help.

Thanks,

Cally

Jul 23 '05 #5
Katie (ze**********@hotmail.com) writes:
So based on your suggestion, I tried this:

update TargetTable set TargetTable.TargetFloatValue = (select
convert(float, convert(nvarchar, OtherTable.NTextValue)) from
OtherTable where OtherTable.ID = @id) where TargetTable.ID = @id

And I get the following error:

"Error converting data type nvarchar to float."
Which in itself is not that surprising. I would expect most ntext
columns in this would have values that are not convertible to float.
Which really surprises me because it is basically what you have
written and because the following works:

updatetext TargetTable TargetTable.NTextValue @ptrText 0 NULL
OtherTable.NTextValue @valuePointer

update TargetTable set TargetTable.TargetFloatValue = convert(float,
convert (nvarchar, TargetTable.NTextValue)) where TargetTable.ID =
@id


Then again, it's funny if one thing works but not the other.

I don't have that much ideas, but then I have not seen the contents
of these ntext columns. Nor do I know why you are doing all this. What
I can suggest is that do a select on the two tables, and see whether you
have the same data. You could also post a script with CREATE TABLE
statements for the table and INSERT statements with some data that
fails you.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sunshinenewton | last post by:
Hi, I want to know is there any function in JS the same as "sprintf" in C language? Thanks a lot !
7
by: nephish | last post by:
Hullo all ! i have a real easy one here that isn't in my book. i have a int number that i want to divide by 100 and display to two decimal places. like this float(int(Var)/100) but i need it...
2
by: respect | last post by:
i want to convert real float number to 32-bit IEEE binary format in C++ ? plz help me in finding the codes as fast as u can ] Example for input -6.5, the output should be. 1 10000001...
15
by: Kay Schluehr | last post by:
I wonder why this expression works: >>> decimal.Decimal("5.5")**1024 Decimal("1.353299876254915295189966576E+758") but this one causes an error 5.5**1024 Traceback (most recent call...
7
by: Partho | last post by:
I have a float variable which I need to add to a short variable. How do I do this? Do I have to typecast or is there a way around? I tried typecasting the float to a short, but that gives me a 0 or...
9
by: cool17 | last post by:
hi guys I am writing a code for to covert expression to string so how is this going to be possible in C? i know for string to float is using atof() so what about the other way round? thx
11
by: redefined.horizons | last post by:
I'm still pretty new to Python. I'm writing a function that accepts thre integers as arguments. I need to divide the first integer by te second integer, and get a float as a result. I don't want...
4
by: Yasin Cepeci | last post by:
I ve get float data from serial port. I ve taken it in the form of hex by modbus protocol. I know it is float but I couldnt convert it there is a few sample data below; B3 33 43 34 = 180.699997...
1
by: leedatkinson | last post by:
Hi, I'm pretty new to using SQL as a long standing Access users all these field types are a bit much... I have a ntext field that I need to convert to a nvarchar. I have tried cast and convert and as...
7
by: Udara chathuranga | last post by:
How can I convert binary float number into a decimal float number ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.