See here on how to create a package for the export:https://community.spiceworks.com/topic/843412-export-sql-view-to-csv-using-sql-server-agent#entry-4408368
And here on how to schedule it:
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How can we schedule sql server agent job to fetch all records from the table to the CSV file end of every week in ssms, give me steps to complete task .
See here on how to create a package for the export:https://community.spiceworks.com/topic/843412-export-sql-view-to-csv-using-sql-server-agent#entry-4408368
And here on how to schedule it:
While creating the job, in the step provide the SQL command to export the data.
Select "Transact-SQL script (T-SQL)".
Select the database containing the table you want to export.
You can use a command with BCP like this:
DECLARE @cmd varchar(1000)
SET @cmd = 'bcp "SELECT * FROM YourDatabase.dbo.YourTable" queryout "C:\path\to\your\file.csv" -c -t, -T -S ' + @@servername
EXEC xp_cmdshell @cmd
Then try to create a new schedule for this job with the following
Make sure that the SQL Server Agent service is running, as it is required to execute scheduled jobs.
The account running the SQL Server Agent job must have sufficient permissions to execute the BCP command and write to the file system.
xp_cmdshell
command might be disabled on your server for security reasons. If it's necessary to enable it, you can do so by running: EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
The first step is to determine the exact requirements. What table? Where should the file land? What is the exact format of the file? Can you go with just plain commas or semicolons as the delimiter, or you need to consider that the delimiters may be in the data? What is the purpose of the file? What other system will ingest it? What tool do you want to use to generate the file? Many sites use SSIS, SQL Server Integration Services, but far from all.
Once you have the code to produce the file, scheduling the job in Agent should be the easiest part.
If you have further questions, please let us know.