I had data in Excel like
7540006
7540447
But when I import the data into SQL Server
, it is saved as
7.54001e+006
7.54045e+006
So now when I try to convert it to back to original state, it's not ending up with the correct value.
I have tried following queries for conversion
declare @a varchar(40)
set @a = '7.54001e+006'
declare @b decimal(27, 12)
SELECT @b = CONVERT(REAL, @a, 2)
SELECT LTRIM(RTRIM(str(@a))), LTRIM(STR(@a))
SELECT CAST('7.54001e+006' as REAL)
and the output I am getting is addition of 3 to original value for all methods i.e.
7540010
7540050
How do I convert it back to original state ??
To change scientific notation to standard notation, we reverse the process, moving the decimal point to the right. Add zeros to the end of the number being converted, if necessary, to produce a number of the proper magnitude.
Convert scientific notation to decimal formDetermine the exponent, n , on the factor 10 . Move the decimal n places, adding zeros if needed. If the exponent is positive, move the decimal point n places to the right. If the exponent is negative, move the decimal point |n| places to the left.
TO_NUMBER converts a string to a number of data type NUMERIC. TO_CHAR performs the reverse operation; it converts a number to a string. CAST and CONVERT can be used to convert a string to a number of any data type. For example, you can convert a string to a number of data type INTEGER.
Use the CAST() function to convert an integer to a DECIMAL data type. This function takes an expression or a column name as the argument, followed by the keyword AS and the new data type. In our example, we converted an integer (12) to a decimal value (12.00).
Try the following query which gives the exact value
select CAST(CAST('7.54001e+006' AS FLOAT) AS bigint)
All data is stored as Unicode string 255 (DT_WSTR)
in excel
.
Read excel
data as Unicode
form. then do conversion in ssis
or database
using.
SELECT CAST('7.54001e+006' as REAL)
In excel data source >> connection manager >>Data access mode == QUERY
SELECT * FROM [SheetName$]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With