473,498 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concatenate float data type

I have a need to make a group of records 'unique' by concatenating a
foreign key value to another field, the two are float and varchar
type. Now, I'll have to cast the float column, but then I end up with
something like this:

'2.20824e+006 02316.PENDING00097840-CC'

The float value actually is: 2208239

How can I get a straight up number to text conversion of this value? I
tried Cast to varchar, that doesn't work.

Any help would be greatly appreciated, thank you!
Oct 16 '08 #1
5 10114
You can cast first to DECIMAL and then to character data type, or use
the STR function:

CREATE TABLE Foo(
keycol INT PRIMARY KEY,
datacol FLOAT);

INSERT INTO Foo VALUES(1, 2208239);

SELECT LTRIM(STR(datacol)),
CAST(CAST(datacol AS DECIMAL(10, 0)) AS VARCHAR(20))
FROM Foo

--
Plamen Ratchev
http://www.SQLStudio.com
Oct 16 '08 #2
On Oct 16, 10:12*am, Plamen Ratchev <Pla...@SQLStudio.comwrote:
You can cast first to DECIMAL and then to character data type, or use
the STR function:

CREATE TABLE Foo(
* keycol INT PRIMARY KEY,
* datacol FLOAT);

INSERT INTO Foo VALUES(1, 2208239);

SELECT LTRIM(STR(datacol)),
* * * * CAST(CAST(datacol AS DECIMAL(10, 0)) AS VARCHAR(20))
FROM Foo

--
Plamen Ratchevhttp://www.SQLStudio.com
Thank you, that worked famously.
Oct 16 '08 #3
>I have a need to make a group of records [sic: rows are not records] 'unique' by concatenating a foreign key value to another field [sic], the two are float and varchar
type.<<

NO! Keys are discrete values by definition. FLOAT is an approximate
data type and cannot be a key. Please read any article on flaotign
point math and the IEEE Standards. When you test floats for equality,
there is this epsilon; a small value which matches two values when
they are "close enough" to each other. Since floats were only meant
to be used for computations, this works fine.

You need to use an exact numeric type or CHAR(n) for keys. Or decide
that you never want data integrity.
Oct 17 '08 #4
I have a need to make a group of records 'unique' by concatenating a foreign key value to another field, <

Without having more details, it sounds to be a candidate for a
compound primary key.

CREATE TABLE Foo
(bar1 DECIMAL(10,5) NOT NULL, -- something instead of FLOAT
bar2 VARCHAR(30) NOT NULL
REFERENCES Foo2(bar2), -- the foreign key
PRIMARY KEY(bar1, bar2)); -- compound key, no duplicates

brgds

Philipp Post
Oct 21 '08 #5
>Without having more details, it sounds to be a candidate for a compound primary key <<.

No! Think about it. They are an approximate computation numeric.
Entities are discrete by their nature. There is no such thing as a
approximate key. This is a problem with (longitude, latitude) pairs
for a location and why GIS uses a grid system of triangles instead.
Oct 22 '08 #6

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

Similar topics

24
3493
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing the code. Thank you. .. Facundo
21
4487
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
3
2618
by: Dmitrii PapaGeorgio | last post by:
how would i print a number in float value without negative numbers? thanks for any advice...
1
26920
by: jaYPee | last post by:
I have created a stored procedure that contain this field (below) in order to meet certain criteria. But my problem is when I try to run the stored procedure I encounter an error "Error converting...
2
6253
by: Sisnaz | last post by:
I'm reading byte information from a C++ program via TCP sockets. At one time I thought I came across away to convert C Float data type into a VB single data type. I'm reading the C data type in...
2
19512
by: safren | last post by:
1. In c++ (or any other language) I'm copying bit by bit to a double variable dob_var. 2. If I copy dob_var to dob_var2 which is also a double I do not lose information. 3. This implies that the...
2
5326
by: Mike | last post by:
I'm running DB2 v7 for z/OS. When I use SPUFI, SELECT CAST(6.0 AS FLOAT)/CAST(10.0 AS FLOAT) FROM SYSIBM.SYSDUMMY1 returns 0.6000000000000000E+00. When I use DSNTIAUL,DSNTEP2, or DSNALI (call...
3
2840
by: RN1 | last post by:
Consider the following code snippet: <% Dim intA, strA, strB intA=5 strA="Hello World" strB=strA+intA Response.Write(strB) %>
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6885
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...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.