Create SQL Agent job to execute a query and save the results to a text tile

I would like to create a SQL Agent job to execute a simple query and save the results to a text file daily.  The query is a simple one like the following:

select partnbr, descr, salesdesc, upc, cat1 from tbl_itemsPT
order by partnbr asc

What is a good way to do this?
navajo26354Asked:
Who is Participating?
 
Anthony PerkinsCommented:
Execute SQLCmd from SQL Server Agent as follows:
sqlcmd -S YourServerName. -d YourDatabaseName -Q "select partnbr, descr, salesdesc, upc, cat1 from tbl_itemsPT order by partnbr asc" -oC:\YourTextFileGoesHere.txt

Open in new window

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.