Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to run scripts within an SSIS Package and how to execute an SSIS Package from a SQL script Expand / Collapse
Author
Message
Posted Thursday, October 01, 2009 7:50 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, December 08, 2009 9:00 AM
Points: 44, Visits: 162
New user to SSIS.

Used the Import/Export Wizard to create a SSIS package to extract data from Excel and import the data into an existing SQL table. Using the Flat File connection type. Some of the data has comma's in it and the import puts quotes around the strings with comma's in them. Need to remove the quotes in the SQL table so wrote the scripts below to do so and they work fine.

1) How do I include the replace/trim sql scripts in the SSIS package? In other words I want to have the SSIS package run the scripts to remove the quotes as part of the package process. Where and how is this done in SSIS?

2) Can a SSIS package be executed from within a SQL script? I would like to use a command button in my application that would run a SQL script or utility that would locate, call and execute the SSIS package. Can this be done and if so, how?

Thanks.


Quote Cleanup Scripts:


UPDATE dbo.IMP_tblImport
SET CompanyName = REPLACE(CompanyName,'"',' ')
WHERE CompanyName LIKE '%"%'

update dbo.IMP_tblImport
set companyname = (LTrim(Replace(CompanyName, ' ', ' ')))


UPDATE dbo.IMP_tblImport
SET Comments = REPLACE(Comments,'"',' ')
WHERE Comments LIKE '%"%'

update dbo.IMP_tblImport
set comments = (LTrim(Replace(Comments, ' ', ' ')))

Post #796334
Posted Thursday, October 01, 2009 8:09 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
1) Include a SQL Script Task in the control-flow, probably before your data-flow task runs.

2) Yes, but it is a Kludge and a potential security issue. SSIS, is not really meant for the development of end-user tools or functionality, it's really targeted at implementing operational features and background tasks.

However, if you feel the you must have this here are your options:

A) Have your client applications/SW run the SSIS package itself by using DTExec.exe at the command line. This is easily the most direct, least kludgey solution and it generally bypasses the security issues (because it just uses the Users or the Apps authorization, hopefully).

B) Write a stored procedure that uses sp_cmdshell to execute the package DTExec, at the command-line, from SQL Server. This works, but is obtuse (because you have to go out to DOS and then DTExec has to log back into SQL Server), and also could be a security problem.

C) Define a SQL Agent SSIS Job Step to run your package. This works, is probably secure, but is hard to implement (it's a PITA trying to run a Job from a session connection), and has reportability issues (as in, it runs asynchronously in another session, so your user will not know when its done or whether is was sucessful or not).


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #796351
Posted Thursday, October 01, 2009 9:30 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, December 08, 2009 9:00 AM
Points: 44, Visits: 162
Previous reply:

1) Include a SQL Script Task in the control-flow, probably before your data-flow task runs.

I know that there are 2 panes in BIDS that display the different flows but not sure how to access or edit them to place the script.
Can you give me details on how to do this? I am relatively new to SSIS.
Post #796425
Posted Thursday, October 01, 2009 10:00 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
Control-flow works like you probably think it does. You drop tasks on it and then, connect their arrows to control the order and conditions of execution.

Data-flow, is really the internal data routing of a Data
Transformation task. Once you have a Data Transformation task in your control flow, then you open it up to go to it's data-flow where you can drop components and then use the arrows to control how the data is piped from component to component. However, If you do not have one of those, then you don't have to worry about it (for this question, anyway).

----------

However, longer term, if you are planning to use SSIS, then you will need to learn all of this. It's a huge and complicated subject, and I strongly recommend that you look around for some books or articles to help you get started with it.


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #796456
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse