March 31, 2008 at 3:37 am
hi
how can we generate the data in csv files of database tables by using sql query?
regards
March 31, 2008 at 3:45 am
You have two options: Use OPENROWSET clause or create a Linked Server to the CSV file and insert into it like a normal table.
March 31, 2008 at 9:54 pm
An oldie but a goodie BCP has been around for years.
Check 'http://msdn2.microsoft.com/en-us/library/ms162802.aspx'. Unlike a lot of MS help this is pretty good and comes with lots of examples.
One caution ... you have to mess with it a bit ... there are lots of switches!
March 31, 2008 at 11:58 pm
Heh... I'm thinking that's more than two options right there 😉 Lets see... DTS, OSQL query, SP_OA* sprocs... there's a couple more, but I forget.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 1, 2008 at 9:41 am
April 1, 2008 at 10:53 am
I agree... he must be busy on Simple-Talk. We should pay him a visit. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
April 2, 2008 at 6:19 am
I hope this isn't too simplistic, but how about just using concatenation strings? E.g.,
SELECT Field1 + ',' + Field2 + ',' + Field3 --etc.
From Table;
You get rows of field data separated by commas. In SQL 2000 use DTS to take this query and put it into a Text file. I'm new to 2005 but I'm sure there's a way to accomplish the same task.
Even simpler, just use Query Analyzer and set you output option to text (as opposed to grid) or in 2005, use the Management Studio Option for output as "Results to File".
I'm sure you recognize that there can't be commas in the field values or this approach fails. If you know commas are present in the field values, use a different delimiter, like the pipe character (|).
I hope I didn't misunderstand your question.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply