Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Importing flat file dates in ssis

Posted on 2011-02-16
9
Medium Priority
?
1,548 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 668 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1332 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 1332 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

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…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

927 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