SQL Query saving output to file with date

Posted on 2012-09-06
Last Modified: 2012-12-15
I need to run an automated query daily and update the information daily. I have created the quert script however I need help with writing script for the Export of the file:

I need to export the file to a Flat file, Lines Seperated by CLRF Colum Deliniated by Semicolon to a file with a file name such as "filedate.txt" so I need to know how to script saving the query below with the filename as date.

We are using Automate and the script is:

  Set @dt = GETDATE()
  FROM [Stage].[dbo].[ExchangeRate]
  WHERE PriceDate =
  (SELECT MIN(PriceDate)
  FROM [Stage].[dbo].[ExchangeRate]
  FROM [Stage].[dbo].[ExchangeRate]))

Question by:KarlSolid
    LVL 92

    Expert Comment

    by:Patrick Matthews
    I would create an SSIS package to run the export, and then schedule a SQL Server Agent job to execute the package.
    LVL 14

    Expert Comment

    by:nishant joshi
    for achieving this you have to create below mention things:

    1)create ssis package
    2)create schedule job

    create ssis package in which add data flow task.
    In dataflow task,source as your query from sql and destination is your text flate file.
    and in connection of flate use expression of date time.

    and for execution ssis package create one job..


    Accepted Solution

    Do you have any idea where I can find the Code for the Datetime Expression>
    LVL 14

    Expert Comment

    by:nishant joshi
    please check attached image...

    image will give you more understanding than words

    DATETIME ExpressionThanks

    Author Closing Comment

    Question abandoned and closed

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Introduced in Microsoft SQL Server 2005, the Copy Database Wizard ( is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now