[Note from Pinal]: This is a new episode of Notes from the Field series. SSIS is an interesting concept. There are more hidden features with SSIS than any other product. Additionally, there are many visible features which are not known to most of the people. Earlier I mention to SQL developer that they can execute SQL queries from SSIS they looked at me like they have seen the ghost. They always thought that they can only do the task in SSIS which are available to them in the tool box. Well, I think when I will get the similar question next time, I am going to forward them a link to this blog post. Andy has explained in very simple words how one can execute SQL Task in SSIS.
With “SQL Server” included in the name of SQL Server Integration Services (SSIS), it is easy for people to assume SSIS is simply a database tool or accessory. Let there be no mistake, SSIS is a software development platform. To give you a better understanding of how to use SSIS as a development platform, I’ll write a series of blogs that step through how to use Control Flow tasks. This first article will cover the Execute SQL Task.
When developing solutions with SSIS, I use a handful of Control Flow tasks:
- Execute SQL Task
- Data Flow Task
- Script Task
- Execute Package Task
- File System Task
- Execute Process Task
This list is a good approximation of which tasks I use most, too – from most-used to least-used. In this article I provide a basic example of configuring the SSIS Execute SQL Task, shown in Figure 1:
Figure 1: SSIS Execute SQL Task
Three things are required to configure an Execute SQL Task:
- Connection Type
- Connection Manager
- SQL Statement
Connection Type
The default Connection Type is OLE DB, as shown in Figure 2:
Figure 2: Available Connection Type Property values
I configure Execute SQL Tasks to execute SQL statements like truncate a table, update or insert a single row of data, or call a stored procedure. I typically use OLE DB or ADO.NET connection types; but I occasionally use ODBC connection types. (When executing parameterized statements I find ADO.NET offers a cleaner interface. I will cover parameters in another article).
After selecting a connection type, selecting the Connection Manager is next. The Execute SQL Task Editor filters the list of available connection managers, displaying only connection managers of the (connection) type configured in the previous step.
Figure 3 shows how to select a Connection Manager:
Figure 3: Selecting a Connection Manager
The last required step to configuring an SSIS Execute SQL Task is to supply an SQL Statement. There are two properties for this: SQLSourceType and SQLStatement. The SQL Source Type property specifies the source of the SQL Statement as one of the following:
- Direct Input
- File Connection
- Variable
The SQL Statement can be entered manually (direct input). It can be stored in a file (file connection) or the SQL Statement can be stored in an SSIS variable (variable). In most cases you will manually enter the query as shown in Figure 4:
Figure 4: Entering the Query
Right-click the task and click “Execute Task” to test the task configuration. Or simply press the F5 key to execute the entire SSIS package, as shown in Figure 5:
Figure 5: Success!
You now know the basics of configuring an SSIS Execute SQL Task. Go code!
:{>
If you want to get started with SSIS with the help of experts, read more over at Fix Your SQL Server.
Reference: Pinal Dave (https://blog.sqlauthority.com)
3 Comments. Leave new
wow this article solved my issue. Great ! and Thanks a lot :-)
wow this article solved my issue. Great and thanks a lot :-)
Hi Thanks for all your tips :D
I would like to truncate my table in my Data Flow, just before writing new data, so the tables is empty as little time as possible…
Do you have an idear on how to do this best possible?