Dynamically extract data from Sql table into flat file

Prajakta Sonawane 1 Reputation point
2022-09-21T15:41:14.31+00:00

Hi all,
I’m new to SSIS and had a question.
I have a table with fields ID, Filename, Filecontent.
I want to give ID and DestinationFolder as input and the output should be all flat files with ID greater than or equal to the input with the Filecontent and Filename as the actual file name of the flat file.
Eg: Id , Filename, Filecontent => (1, abc, ‘how are you?’), (2, def, ‘I am good,) , (3, ghi, ‘Good to know’)
Input: ID = 1 , destination folderpath: ‘C://‘
Output :
abc.txt (content in the file: ‘how are you?’)
def.txt (content in the file: ‘I am good’)
chi.txt (content in the file: ‘good to know’)

Please let me know if it’s possible in SSIS or if my question is unclear.
Thanks you very much!

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ZoeHui-MSFT 41,491 Reputation points
    2022-09-22T05:29:13.623+00:00

    Hi @Prajakta Sonawane ,

    What about create a store procedure in the database first and then run the query via SSIS?

    create table test0922( id int, Filename varchar(max), Filecontent varchar(max))  
    insert into test0922 values  
    (1, 'abc','how are you?'), (2, 'def', 'I am good') , (3, 'ghi', 'Good to know')  
      
      
    CREATE PROC outputdata   
    @id INT   
    AS  
    SELECT Filename+'.txt(content in the file:'+Filecontent+')' as filepatht FROM test0922  
    WHERE id>=@id  
    GO  
    

    And the you may store query to variables to pass the parameter like shown below.

    243761-untitled.png

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.