SQL Query saving output to file with date

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:

DECLARE @dt DATETIME
  Set @dt = GETDATE()
 
  SELECT *
  FROM [Stage].[dbo].[ExchangeRate]
  WHERE PriceDate =
  (SELECT MIN(PriceDate)
  FROM [Stage].[dbo].[ExchangeRate]
  WHERE ABS(DATEDIFF(DAY,@dt,PriceDate))=
  (SELECT MIN(ABS(DATEDIFF(DAY,@dt,PriceDate)))
  FROM [Stage].[dbo].[ExchangeRate]))

Ideas?
KarlSolidAsked:
Who is Participating?
 
KarlSolidConnect With a Mentor Author Commented:
Do you have any idea where I can find the Code for the Datetime Expression>
0
 
Patrick MatthewsCommented:
I would create an SSIS package to run the export, and then schedule a SQL Server Agent job to execute the package.
0
 
nishant joshiTechnology Development ConsultantCommented:
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..

thanks
Nishant
0
 
nishant joshiTechnology Development ConsultantCommented:
please check attached image...

image will give you more understanding than words

DATETIME ExpressionThanks
Nishant
0
 
KarlSolidAuthor Commented:
Question abandoned and closed
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.