Importing from Excel to SQL Server: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value - sql

I have the following Excel Workbook:
https://meocloud.pt/link/7cb3ef48-7556-4d36-ab9a-c247d3f7b29d/FichasTeste.xls/
It's formatted to be imported to a SQL Database. The server has the following details:
As you can see the mapping is correct in the importer
When i try to import the excel file, the status is always the same, no matter the modifications i do to the columns with the Date.
242: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
3621: The statement has been terminated.
What should i modify so that those rows can be imported without having that error?

Excel stores dates as integers, if you change the excel field to TEXT you'll see that, but I'm not sure why you're having this problem, you should be able to direclty import from Excel and have dates preserved, at least you can using SQL's import wizard as well as SSIS.
One workaround is using the TEXT() function in Excel to get your date into an acceptable format:
=TEXT(F2,"yyyy-mm-dd")
I like importing from Excel using OPENROWSET(), but that requires some additional setup and has it's own drawbacks:
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\YourExcelFile.xls', [Sheet1$])

Related

AsterixDB unable to import datetime when importing from CSV file (SQL)

I am attempting to load a database from a CSV file using AsterixDB. Currently, it works using only string, int, and double fields. However, I have a column in the CSV file that is in DateTime format. Currently I am importing them as strings, which works fine, but I would like to import them as the SQL DateTime data type. When I try changing my schema and reimporting I get the following error:
ERROR: Code: 1 "org.apache.hyracks.algebricks.common.exceptions.NotImplementedException: No value parser factory for fields of type datetime"
All entries are in this format 02/20/2010 12:00:00 AM.
I know this isn't exactly inline with the format specified by the Asterix Data Model, however, I tried a test line with the proper format and the error persisted.
Does this mean AsterixDB cant parse DateTime when doing mass imports? And if so how can I get around this issue?
Any help is much appreciated.
Alright, after discussing with some colleagues, we believe that AsterixDB does not currently support DateTime parsing when mass importing. Our solution was to upsert every entry in the dataset with the parsing built into the query.
We used the following query:
upsert into csv_set (
SELECT parse_datetime(c.Date_Rptd, "M/D/Y h:m:s a") as Datetime_Rptd,
parse_datetime(c.Date_OCC, "M/D/Y h:m:s a") as Datetime_OCC,
c.*
FROM csv_set c
);
As you can see we parse the strings using the parse_datetime function from the AsterixDB Temporal Functions library. This query intentionally doesn't erase the column with the DateTimes in string format, although that would be very simple to do if your application requires it. If anyone has a better or more elegant solution please feel free to add to this thread!

Excel Data values returned as null when load to SSIS

I have an odd thing happening with importing data from Excel to SQL Server.
This is my sample source data
The value become null after import to SQL Server
Basically, other part of excel work well. But only for this area, the value become null. The data type is float which I haven't convert it to numeric or nvarchar.
Thank you for your help.

How to save date value in dd/mm/yyyy into excel from SSIS where TimeZone=Eastern in server

I have an SSIS package, which I am running a Stored Procedure and save the resultset in a object type of variable (as temptable) in the control flow, and in the data flow I am using a script to retrieve data from the object type of variable saving the result set in an excel file.
Everything works well except the date column. It should be in dd/mm/yyyy format, however whatever I have tried I could not prevent it to be in m/d/yyyy format in the excel.
What I have tried are:
1- Added this to connectionstring of Excel ConnectionManager -> Excel 12.0;HDR=Yes;IMEX=0;Readonly=False and Excel 12.0;HDR=Yes;IMEX=1;Readonly=False. Both did not work.
2- Added a Derived Column task, derived a new "DerivedMyDate" column as STR, WSTR, Date. Used this column to save the date value in the excel file, where type is set as STR and DATE. None of my trials worked.
3- Added Data Conversion task, tried all same things that I've tried in 2nd step, none worked.
4- Added a dummy first line in the excel, where the data column is like 15/01/1900. Does not work, it is adding the other rows below where date values in m/d/yyyy format.
Checked those pages, the answers did not work for me:
Date format problem using SSIS for Excel into SQL Server
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/7e34a0af-a744-4a51-b925-3284d0fba296/problem-in-date-format-while-exporting-to-excel-destination-from-flat-file-source-in-ssis?forum=sqlintegrationservices
TimeZone of my PC: (UTC-05:00) Eastern Time (US & Canada), changing this is not an option.
Any help or advice would be appreciated.
I will try to propose a little modify a T-SQL query in a next solution for you.
At the step of extracting data from the Stored Procedure, if this one returns not many columns, you should declare a table variable with a names, types and columns count appropriated with your stored procedure columns, for example #var. Then you need to pass executed stored prococedure result in variable,
INSERT INTO #VAR
EXEC sp_your_stored_prodedure
At the last step you should retrieve data not from stored procedure, but from #var, and to add in the select statement new field with CONVERT T-SQL function with date format 103 :
SELECT
v.*
,CONVERT (NVARCHAR, v.date_field, 103) as target_date_format
FROM #var AS v
After this, you may work with this DataFlow and Date in the appropriate format.

Handling Dates while copying from Excel to SQL server database table in Talend

I am copying data from an Excel workbook to the SQL server database table.
One of the column in my Excel sheet has Dates, which I am generating using Rand function.
If I keep data types of my columns as string in both my Excel input and SQL output.
I get an error which says
"Conversion failed when converting character string to smalldatetime data type."
If I keep my datatypes as Date it gives as error which says
"The cell format is not Date in ....(cell address)"
In my table's definition in SQL server. It has data type as 'smalldatetime'.
To solve this problem I am using tConvertType.
But I am getting an error which says:
"The cell format is not Date in ....(cell address)"
I have attached my job's screenshots.
you can also use TalendDate.parseDate method for conversion...
this can be used in expression in tMap..so your flow with reading date from excel as String and converting it to date using TalendDate.parseDate("yyyy-MM-dd HH:mm:ss","")
input -> tmap -> tmssqloutput components.
You need to convert the type in your Talend job.
Read the date in as a string and then use a tConvertType component to convert the type from string to a date type with a specific date format. You should then be able to send this to the database as a smalldatetime data type

Excel Date Field Import Problem in Oracle SQL Developer

I have an Excel file (which has data imported from Oracle 10G Database) one of the fields is a
Date Filed which has values like 28-JAN-11 03.25.11.000000000 PM ( Date field is Oracle Time
Stamp(6) in Database )
When I am trying to Import that Excel file to another Oracle 10 G database (for another database/application), I get an error because the data field is not being recognized by Oracle 10G --> Import is being done by ORACLE SQL Developer (Table (field) has TIMESTAMP(6) as the datatype)
How can I import that field? For time being I made the TIMESTAMP to VARCHAR2 and its working but I could not convert that to Date field again in C# CODE ( it says not a valid date type).
You likely need to change your SQL Developer settings.
Tools->Preferences->Database->NLS
Modify the Timestamp Format field to conform to the data format in your Excel spreadsheet. Not how it appears in the first database, but what it looks like in your spreadsheet. For example, in my instance, the data in Excel was:
ID DT
1 05/19/2011 10:16 PM
I changed the format in preferences to MM/DD/YYYY HH:MI AM
and was able to import successfully, after initially getting the same error you reported before changing preferences.
You may want to change the way your data is imported into Excel originally if you need more precision from your time values.
During the import wizard process (column definition screen), select the date type field on the left panel under 'Source Data Columns' and type in the expected format in the 'Format' text field. For example, MM/DD/YYYY or whatever the date format is in your import file for that field.