Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JTProg
Starting Member
24 Posts |
Posted - 2006-12-19 : 10:37:28
|
| How can I bulk export a query to a csv file using a stored procedure? I want to schedule a job to run once a week to export this query.Declare @Week int Declare @Year int SELECT dbo.tblBat.BatchID, dbo.tblBat.Department, dbo.tblBat.PreparedBy, dbo.tblBat.Type, dbo.tblErrors.ErrorMessage, Convert(char(10), dbo.tblErrors.DateField, 101) AS 'Error Date'FROM dbo.tblBat INNER JOIN dbo.tblErrors ON dbo.tblBat.BatchID = dbo.tblErrors.BatchIDWHERE (dbo.tblBat.Type = N'New Purchase') AND (DATEPART(Week, DateField) = @Week) AND (DATEPART(year, dbo.tblBat.PurchaseDate) = @Year) AND NOT(dbo.tblErrors.ErrorMessage=' ')ORDER BY dbo.tblBat.BatchID, dbo.tblBat.PreparedBy |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-19 : 10:48:34
|
| You could use GETDATE() function?SELECT @Week = DATEPART(week, GETDATE()), @Year = YEAR(GETDATE())And then have a job running the stored procedure at a regular interval?Peter LarssonHelsingborg, Sweden |
 |
|
|
JTProg
Starting Member
24 Posts |
Posted - 2006-12-19 : 11:54:12
|
| I'm unfamiliar with the bcp export process. I know how to perform an export to a .csv file from within a dts package, but I'm really hoping to utilize a stored procedure to export the .csv file instead. Is this possible? If so, can someone help me out with this or even point me in the right direction. Thanks. |
 |
|
|
|
|
|
|
|