Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Need help in Data import

Author  Topic 

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 15:07:24
I am doing a huge data import from a text file to a wide table. I used BUL INSERT for this, there were many data type problems.

Someone on this site (guess it was Peso) suggested to import the data in a STAGING table with all varchar columns.

BULK INSERT went well.

Now I need to import to actual table from staging table. I am planning to use SSIS, data flow task. On the source I am using a query with CONVERT function. This query fails because of data type compatibility (for the same reason I had imported data into a all varchar table earlier!)

Is there a way to segregate these bad records?


------------------------
I think, therefore I am - Rene Descartes

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-03 : 15:12:55
Yes. You can use Data Conversion task to correct data type and also with Lookup Transformation task you can direct it to other destination if you have any.
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 15:24:55
Thank you Sodeep.

I don't need [Data Conversion task], becuase data is already converted at the source using a CONVERT function in the SELECT statement. I need to capture the errors resulting because of CONVERT.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-03 : 15:45:30
Use configure error output in your OLEDB destination task and redirect row with red arrow pointing to other destination OLEDB destination .
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 15:54:58
I got yor point.

Why should I do it on the DESTINATION? I am expecting error on the SOURCE. I have done your suggestion in the SOURCE, how ever the bad rows are not getting transferred.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-03 : 16:04:20
Didn't understand your requirement clearly? How will you get error in Source table(staging) in SSIS? Did you create destination table with same datatype ? Also where you want to capture error?
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 16:09:35
0.My oledb source is not a table. It is a query.
1. Staging and destination tables have same number of columns and same name.
2. However at staging all the columns have VARCHAR data type
3. I am using a tsql query at the source. The query uses convert function to convert as per the destination columns.
4. I want to capture the error at source.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-03 : 16:19:46
The question is : How SSIS will know you have bad rows? You need to have some lookup table to determine?
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 16:25:51
Convert function raises error - for e.g. when ever it tries to convert character to int. I want these rows to get captured.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-03 : 16:37:11
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101225
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 17:01:28
Ok; One last question.

1. My source table has varchar for date info.
2. Target tables has proper datetime data type
3. Where can i use the CONVERT function?

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-03 : 17:03:26
Can't it do an implicit conversion?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 17:08:45
no. The text file is from tera data. It has a different date format, that i snot supported in SQL Server.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-03 : 17:10:26
Although you can do this inside SSIS/DTS in the transformation, I prefer to do it inside SQL Server. I always create a staging table that matches the data types of the source. After the data is loaded into the staging table, you can then use T-SQL to transform the data and in your case perhaps a CONVERT or something else will do it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 17:17:57
1. The staging table is a wide table.
2. all the columns in staging table are VARCHAR
3. when I use CONVERT it fails many time at different places.
4. How to capture these errors.
5. I don't mind NOT using SSIS.


------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-03 : 17:19:29
You'd have to give us more information about step 3.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 17:25:44
3. Lets say I have 100 datetime coulmns in the table.

I am trying someting like SELECT CONVERT(datetime,col1,111).......100 cols from tb_name

I get a generic error something like - can not convert to datetime.

Now i don't know which of the 100 columns caused this problem. Hope it is clear now.


------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-03 : 17:29:23
I'd narrow it down via pure SELECT statements. Remove a few columns at a time until you narrow it down to the offender.

SELECT CONVERT(datetime, col1, 111), CONVERT(datetime, col2, 111), ...
FROM Table1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-10-03 : 17:35:01
In fact I started like that.

It is really monotonus and scary. The table has around 300 columns. It is DW table. 45 million records.

Single select takes a lot of time.

The elimination process is the last thing i want to use. I was expecting SSIS to give some detailed errors.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-03 : 17:39:29
I doubt it'll provide anymore detail as to what you are seeing in T-SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-03 : 17:39:41
Try the IsDate function too.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
    Next Page

- Advertisement -