How to read from a text file in SQL query ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DataStageBarTen
    New Member
    • Feb 2012
    • 2

    How to read from a text file in SQL query ?

    I am creating a SSIS package which reads from a table & outputs a text file. In the SQL that is being used I have a WHERE condition:
    Code:
    SELECT COLUMN_NAME FROM TABLE_99
    WHERE FISCAL_YR = '2012'.
    Instead of hard coding the year '2012', I would like to pass the year from a text file? That way the user can just change the text file's year when the fiscal year changes.

    How do I pass the year as a parameter into the SQL query?
    or add :
    Code:
    WHERE FISCAL_YR=CAT \\FOLDER\YEAR.TXT
    I am using SQL server management studio (SQL 2008).

    Thank you.
    Last edited by NeoPa; Feb 20 '12, 11:08 PM. Reason: Added mandatory [CODE] tags for you
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Why not just calculate the fiscal year? Then they don't have to input anything.

    Comment

    • DataStageBarTen
      New Member
      • Feb 2012
      • 2

      #3
      Thanks for the reply.
      I already asked the users but since they sometimes run reports using old fiscal year even when the new fiscal year starts.
      So that's not an option.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Well, if you want to use a text file, then you can use a data flow task to copy the year into a table and then use that in your SQL.

        Or, if you know .Net, use a script to populate a variable and use that variable in another variable to calculate the SQL string.

        Comment

        Working...