Click here to Skip to main content
15,891,657 members
Articles / Programming Languages / C#
Tip/Trick

SSIS Tip 1: Using "Select Query" to define source

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
10 Jul 2013CPOL 12.3K   4  
Using coding define SSIS source connection.

Introduction

This tip is continuation with my article posted here. In this article i will demonstrate to use SQL query to create initial OLEDB source, Instead of direct table access. 

Using the code 

Please have look on article mentioned in the Point of Interest section, this will certainly going to help you. Now if you select direct table in SSIS project, you code like this :- 

// Set the custom properties of the source. 
 srcDesignTime.SetComponentProperty("AccessMode", 0); // Mode 0 : OpenRowset / Table - View 
 srcDesignTime.SetComponentProperty("OpenRowset", "[dbo].[SourceTable]"); 

Now for changing code for inclusion of the  SQL query 

string formatSQL = "SELECT * from [dbo].[SourceTable] where [Age] < 31";
// Set the custom properties of the source. 
 srcDesignTime.SetComponentProperty("AccessMode", 2); // Mode 2 : OpenRowset / SQL Command 
 srcDesignTime.SetComponentProperty("OpenRowset", "[dbo].[SourceTable]"); 
 srcDesignTime.SetComponentProperty("SqlCommand", formatSQL);

Here  we have done these changes

  • AccessMode is changed from 0 to 2, i.e. to accommodate the SQL Command
  • New property "sqlcommand" added , which will get actual SQL query, 

Once coded you can check same in the OLEDB source connection here 

Image 1

Points of Interest 

Have a look at the other article of series  

History

Check out more article in this series! 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
He used to have biography here Smile | :) , but now he will hire someone (for free offcourse Big Grin | :-D ), Who writes his biography on his behalf Smile | :)

He is Great Fan of Mr. Johan Rosengren (his idol),Lim Bio Liong, Nishant S and DavidCrow and Believes that, he will EXCEL in his life by following there steps!!!

He started with Visual C++ then moved to C# then he become language agnostic, you give him task,tell him the language or platform, he we start immediately, if he knows the language otherwise he quickly learn it and start contributing productively

Last but not the least, For good 8 years he was Visual CPP MSMVP!

Comments and Discussions

 
-- There are no messages in this forum --