Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Importing flat file dates in ssis

Posted on 2011-02-16
9
Medium Priority
?
1,545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

730 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