Solved

Importing flat file dates in ssis

Posted on 2011-02-16
9
1,526 Views
Last Modified: 2013-11-10
Urgent reply needed.  ...   Importing date columns from a flat file in this format '11/12/2005' however sometimes the date field is blank. The data is coming from the flat file into a table as char(10) then copied over to a table on SQL 2005. (this process worked with DTS) I am now using SSIS 2005 and I am getting an error in ssis and failing.  I've tried to change the oledb destination data type to string to match the char but getting invalid value for cast specification - then tried to change the oledb destination column to datetime instead of string and error again with value could not be converted.  Now, it is failing on some rows because I set the column to ignore error/truncation and some values were passed - so I am thinking that blanks might be the cause? Added an error output to a textfile destination on the specific column and received this in the error column ? -10716076891148 .  I've spent days on this and I have a great headache .. file is needed urgent.  thnx much. forever grateful to whoever can resolve .
0
Comment
Question by:bar0822
9 Comments
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 167 total points
ID: 34911079
<<sometimes the date field is blank. The data is coming from the flat file into a table as char(10) then copied over to a table on SQL 2005.>>

Does the table where you inport date field first allow NULLs? Is this your DTS problem or when you copy data from that table to a SQL 2005 table? check to make sure that all fields have same data type and CAST or CONVERT your date to that data type and FORMAT! it is important to preserve the dd/mm/yyyy in all of them and use appropriate date format for that.
0
 

Author Comment

by:bar0822
ID: 34911569
yes the table allows nulls. Looks like all the fields that I can see in the flat file are mm/dd/yyyy and there are empty strings.  Whatever I do I am getting errors.
0
 
LVL 30

Expert Comment

by:Reza Rad
ID: 34915024
did you used any conversion trasnform after flat file source? or did you used any other trasnform?
if yes, try to configure error output on transforms and redirect error output to another flat file destination.
if no, try to configure error output on flat file source and redirect error output to another flat file destination.

then you can run the package and find out rows which caused error and troubleshoot them.

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:bar0822
ID: 34916883
I redirected the rows to another flat file destination from the flat file source and all the rows were directed to the flat file source including the blanks and the dates which were mm/dd/yyyy and the error code -10716076891148
0
 
LVL 22

Assisted Solution

by:8080_Diver
8080_Diver earned 333 total points
ID: 34918646
You might want to try using ISDATE(yourcolumn, NULL) to preclude the error on all spaces.  To solve the conversion problem, I would use a CASE statement that checks for NULL and, if it is not NULL, then use a CONVERT(DateTime, yourinputcolumn, 101) to properly convert the MM/DD/YYYY date format to a SQL Server DateTime datatype.
0
 

Author Comment

by:bar0822
ID: 34919446
ok. I am just learning SSIS - where do i use the isdate(date column, null)
and case statement?
0
 
LVL 22

Accepted Solution

by:
8080_Diver earned 333 total points
ID: 34919775
Do you have a SQL statement that is accessing the falt file data?

I generally pull flat file data into a staging table that has allof the fields defined as VarChar({somethingappropriate}) and then I use a SQL statement like SQL_1, below, to do the actual insertion of the data into the destination/target table.

In your case (and after a quick Google ;-), you need the INSERT statement to look sort of like SQL_2, below.
-- SQL_1
INSERT INTO targettable
(
 {list of columns} 
)
SELECT {list of columns}
FROM stagingtable;

-- SQL_2
INSERT INTO targettable
(
 {list of columns} 
)
SELECT {list of columns}
       ,CASE WHEN ISDATE(yourquestionablecolumn)= 1
             THEN CONVERT(DateTime, yourquestionablecolumn, 101)
             ELSE NULL
        END 
       ,{list of more columns}
FROM stagingtable;

Open in new window

0
 

Assisted Solution

by:bar0822
bar0822 earned 0 total points
ID: 34920290
I am putting the data from flat file directly into a temp table with (char) datafields but then trying to copy the data from this table into the SQL Table but using an oledb connection destination .. I am not fooling SQL.  I will try your solution above, so grateful for your help.  Will let u know how it goes.

0
 

Author Closing Comment

by:bar0822
ID: 34959172
the solution worked without any problems.  I was able to import from flat file to sql table using convert from a sql statement  - i was having trouble with the data conversion task- ran faster also.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

820 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