I am using openrowset to import a csv file into SQL Server. One of the columns in the csv file contains numbers in scientific notation (1.08E+05) and the column in the table it is being inserted
By default it is importing the value as 1 and ignoring the .08E+05.
I have tried using cast() and convert() to convert the value directly when the query is executed as well as setting up the datatype in the table as a character string and importing it as such. All of these methods have the same behavior where the .08E+05 is ignored.
Is there a way to have the value imported as 108000 instead of 1 without the .08E+05 without having to change the csv file itself?
Setting up the datatype as a varchar and reading in the csv file appears to have the same effect with the following code:
CREATE TABLE #dataTemp (StartDate datetime, Value varchar(12))
SET @insertDataQuery = 'SELECT Date, CSVValue from OpenRowset(''MSDASQL'', ''Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir='
SET @insertDataQuery = @insertDataQuery + 'C:\Data\;'',''SELECT * FROM '+ '11091800.csv' + ''')'
INSERT INTO #dataTemp EXEC(@insertDataQuery)
SELECT * FROM #dataTemp
Not all of the values in the CSV file have the scientific notation and the value without it, e.g. 81000 come across without issue.
SELECT CONVERT(INT, CONVERT(FLOAT, '1.08E+05'));
- the last time I worked on scientific notation I was dealing with performance counters from LogMan, and I definitely needed the decimal places... – Keiko