Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 472351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:04:42+00:00 2026-05-13T00:04:42+00:00

I have a few SQL statements stored in text files. How do I pull

  • 0

I have a few SQL statements stored in text files. How do I pull these files into a string variable in SSIS so that I can use the same query in multiple places?


Answer to questions:

The queries are long and complex, something I’d prefer to edit in a real text editor, not inside the SSIS text boxes. I’d also like the queries to be editable by people who don’t have access to SSIS or don’t know how to use it. Finally, each of the queries is used in a number of different data flows. Correct me if I’m wrong, but if I use the same query in multiple spots I believe I have to either use a variable or re-write the code for each data flow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:04:42+00:00Added an answer on May 13, 2026 at 12:04 am

    Here’s how I did this very thing (after searching everywhere for an answer and finding none.)

    I started with a package that the Export Data Wizard created, so my instructions relate to that. Doing it that way sets up the column mappings. If you didn’t use the Export Wizard to create the package you may have to add columns by hand.

    1. Add a string variable named SQLFileName to the package.
    2. Add a string variable named SQLCommand to the package.
    3. Add a Script Task at the start of the Control Flow.
    4. Edit the Script Task and go to the Script section.
    5. Add SQLFileName to the ReadOnlyVariables section. Set it to
      the path of your .sql file.
    6. Add SQLCommand to the ReadWriteVariables section.
    7. Click Design Script.
    8. Paste in the script below. It just reads in the contents of the
      file specified by SqlFileName into
      SQLCommand.
    9. OK your way out and connect the Script Task to the rest of your control flow.
    10. Go to your Data Flow and select the Source Query. You’ll need to
      edit the properties using the
      properties window. If you use the
      fancy Edit window you’ll get an
      error about the command text not
      being set. It’s because SQLCommand
      is blank at design-time.
    11. Change the AccessMode to SQL Command from variable.
    12. Under SQLVariableName, select SQLCommand.
    13. You’ll see that a red X gets added to the Source Query. That’s
      because the SQLCommand is blank. To
      prevent the red X, change
      ValidateExternalMetaData to False.

    That’s about it. I hope I remembered all the bits. The script is the key part so that you can get the SQL into a variable and then use the variable in the Data Flow.


       Imports System
        Imports System.IO
        Imports Microsoft.SqlServer.Dts.Runtime
    
        Public Class ScriptMain
    
            Public Sub Main()
    
                Try
    
                    Dts.Variables("SQLCommand").Value = System.IO.File.ReadAllText(Dts.Variables("SQLFileName").Value.ToString)
    
                    Dts.TaskResult = Dts.Results.Success
    
                Catch oException As System.Exception
    
                    Dts.TaskResult = Dts.Results.Failure
    
                End Try
    
            End Sub
    
        End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

Stored Procedures in SQL 2005 - with field type NText Im Writing a stored
Let's say I have a fairly simple app that lets users store information on
As part of my integration strategy, I have a few SQL scripts that run
On my C# asp.net webform I have a search page that has roughly 20
I want to ask how other programmers are producing Dynamic SQL strings for execution

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.