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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query Export

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.BatchID
WHERE (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 Larsson
Helsingborg, Sweden
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -