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 2005 Forums
 Transact-SQL (2005)
 Export to CSV or Text

Author  Topic 

sross81
Posting Yak Master

228 Posts

Posted - 2009-05-22 : 13:39:16
Hello,

I have a query that I want to have it automtically create like csv or text file out at a specific file directory when it runs. Is there a way to do this?

SELECT a.first_name, a.last_name,cast(a.date_of_birth as datetime) as DOB,
a.language,
cast( b.appt_date as datetime) as ApptDate,
convert(datetime,stuff(b.begintime,3,0,':')) as begintime,
b.cancel_ind, c.location_name, d.description, e.event
FROM person a
JOIN appointments b ON a.person_id = b.person_id
JOIN provider_mstr d ON b.rendering_provider_id = d.provider_id
JOIN location_mstr c ON b.location_id = c.location_id
JOIN events e ON b.event_id = e.event_id
where b.appt_date >= @startdate and b.appt_date <=@enddate

So for example I want the results of this query to go to a file location like:

U:\Departments\Phone Tree Report

and have it save as a text or csv file and it would be nice if I could add the current date to the end of the file or just overwrite the last one that is out there. Is this something that can be done with SQL?

Thanks in Advance!
Sherri

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-22 : 13:47:45
yup...you can use bcp for that. see this

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/bcp-export-data-to-text-file.aspx
Go to Top of Page

sross81
Posting Yak Master

228 Posts

Posted - 2009-05-22 : 13:59:01
thanks :)
quote:
Originally posted by visakh16

yup...you can use bcp for that. see this

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/bcp-export-data-to-text-file.aspx




Thanks in Advance!
Sherri
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-22 : 14:02:21
welcome
Go to Top of Page
   

- Advertisement -