• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

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?
0
KarlSolid
Asked:
KarlSolid
  • 2
  • 2
1 Solution
 
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
 
KarlSolidAuthor Commented:
Do you have any idea where I can find the Code for the Datetime Expression>
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now