I’ve been asked to export data out of 100 tables.
for each table it would be something like this:
select * from table1
where datepart(yyyy,table1.DOS)=2011
and datepart(mm,table1.DOS)=01
and then:
select * from table1
where datepart(yyyy,table1.DOS)=2011
and datepart(mm,table1.DOS)=02
etc…
i would need to do this for every YEAR and for every MONTH for every table
i need to export these data sets to a CSV
can you please give me some guidance on how i can automate this instead of using the IMPORT/EXPORT wizard manually?
Dynamic SQL with sp_msforeachtable. Here is a link with info and examples:
http://weblogs.asp.net/nunogomes/archive/2008/08/19/sql-server-undocumented-stored-procedure-sp-msforeachtable.aspx