Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Sep 24, 2000

DTS How to...Skip Rows during Import

By Darren Green

7 How to Skip Rows during Import

A common request is how to skip certain rows during an import or data transformation process. DTS can accomplish this, but perhaps the simplest solution is to import data into a staging table, then use standard SQL statements to delete what is not required, before inserting the remaining rows into the final table.

Now back to DTS...
Firstly you can skip header rows by using the First Row property of the DataPump Task, see Advanced properties sheet. The Text File Connection also has a Skip Rows property, see file Properties of the Connection.

For more advanced situations you can control what is actually inserted by using an ActiveX Transformation Script. The default transformation script always ends by setting the function result to DTSTransformStat_OK. This is one of the transformation return codes, or the DTSTransformStatus constants, which can be used to control the transformations behaviour, such as skipping an insert.

To prevent the current rows from being inserted, we return DTSTransformStat_SkipInsert.

 

The following example will skip the insert because our first column is blank, and for this example is assumed to be our primary key:

Function Main()
	If IsNull(DTSSource("Col001")) Then
		Main  = DTSTransformStat_SkipRow
	Else
		DTSDestination("RowID") = DTSSource("Col001")
		DTSDestination("Name") = DTSSource("Col002")
		DTSDestination("Description") = DTSSource("Col003")
		Main = DTSTransformStat_OK
	End If
End Function

 

This example is used to restrict which rows are imported based on a value. This is useful when the source is text file, as you cannot use a query to filter the source rows as you would with an OLE-DB/ODBC compliant data source:

Function Main()
	If DTSSource("Col001") > 4 Then
		Main  = DTSTransformStat_SkipRow
	Else
		DTSDestination("RowID") = DTSSource("Col001")
		DTSDestination("Name") = DTSSource("Col002")
		DTSDestination("Description") = DTSSource("Col003")
		Main = DTSTransformStat_OK
	End If
End Function	


MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM