Help sending results to txt file

  • I'm trying to figure out a way to send the results of a query to a txt file. Is this possible? If so, what is the syntax?

    Thanks in advance.

    Justin

  • Why would you want to do that?

  • You can use the bcp utility from command line.

    bcp "SELECT fname, lname, address, city, state, zip FROM mydb..users order by state, city" queryout Users.txt -c -Smysqlserver -Umyusername -Pmypassword

    Books online has lot of info on this.

  • Because I need to schedule several queries to run overnight and I have to save the results and I'd rather not have to do it all manually.

  • Why not save the results of the query in a reporting table... or send an e-mail with the results of the query??

  • For auditing purposes, I need it as a file, not as just an email. Can I use xp_sendmail to send results as an attachment instead of just putting it in the message body?

  • Ah.  Ok, I got it working. Thanks, guys

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply