Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert Data in Table from float to Integer

Posted on 2013-01-17
3
Medium Priority
?
452 Views
Last Modified: 2013-01-18
RecordNumber	TLInstance	Timestamp	Hundredths	Type	Data	Flags
139543	101	2013-01-17 09:15:00.000	4	0	1.91663e+006	0
139544	101	2013-01-17 09:30:01.000	52	0	1.91673e+006	0
139545	101	2013-01-17 09:45:00.000	11	0	1.91682e+006	0
139546	101	2013-01-17 10:00:01.000	49	0	1.91692e+006	0
139547	101	2013-01-17 10:15:00.000	20	0	1.91701e+006	0
139548	101	2013-01-17 10:30:01.000	69	0	1.91709e+006	0
139549	101	2013-01-17 10:45:00.000	12	0	1.91718e+006	0
139550	101	2013-01-17 11:00:01.000	53	0	1.91727e+006	0
139551	101	2013-01-17 11:00:01.000	53	1	259::42	0
139552	101	2013-01-17 11:06:01.000	70	3	11	0
139553	101	2013-01-17 11:06:01.000	70	3	00	0
139554	101	2013-01-17 11:15:00.000	0	0	1917363	0
139555	101	2013-01-17 11:30:00.000	0	0	1917455	0
139556	101	2013-01-17 11:45:00.000	0	0	1917548	0
139557	101	2013-01-17 12:00:00.000	0	0	1917641	0
139558	101	2013-01-17 12:15:00.000	0	0	1917735	0
139559	101	2013-01-17 12:30:00.000	0	0	1917831	0

Open in new window

Hi,

I have a application archiving data every 15mins into a database. I've recently changed the datatype of the data going into the table (the table column is still a Varchar(32)), but  now need to convert the Historic data to an integer.

to better display my requirement, I've attached a sample of the old and new data. I could really use an update query to go through all of the rows, and convert from the old to new datatype, so that is displays correctly in the application. Currently, the application on displays a 1 when the Data is recorded as 1.91663e+006. I need to convert this 1.91663e+006 to its actual value of 1916630.

Any help is appreciated.
0
Comment
Question by:wint100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38787023
this small code shall help:
declare @table table ( field varchar(20)) 
insert into @table values ( '1.91663e+006' )

select t.field
  , left(t.field, charindex('e+', t.field)-1) base
  , right(t.field, len(t.field) - charindex('e+', t.field) -1 )
  , cast(left(t.field, charindex('e+', t.field)-1) as float) * power( 10, cast(right(t.field, len(t.field) - charindex('e+', t.field) -1 ) as int ))
from @table t

Open in new window

0
 
LVL 1

Author Comment

by:wint100
ID: 38787068
Can this be used to update all historic data (2 years of samples recorded @ 15min intervals) on  table called Data? I need it to update all rows in the table.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38787211
this would do, then:
 
UPDATE  t
   SET Data	= cast(left(t.Data	, charindex('e+', t.Data	)-1) as float) * power( 10, cast(right(t.Data	, len(t.Data	) - charindex('e+', t.Data	) -1 ) as int ))
FROM yourtable t
WHERE Data	like '%e+%' 

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question