April 21, 2005 at 10:30 am
Hi folks,
I am in some desperate need of a T-SQL expert....
I am trying to split a large table of 147,000 records in SQL server into 147 x 1,000 csv files. Is this easy to do? I am at the end of my tether with DTS and was hoping for a solution in T-SQL. Can anyone help??
April 21, 2005 at 11:41 am
Is there a reason you can't just create 1 file?
April 21, 2005 at 1:00 pm
The answer is yes, it is easy to do. (Assuming you're SA and are going to run it as SA)
Write a TSQL select statement that creates/formats a 147 BCP (DOS) statements. Run this so that those are spit out to a dos batch file and execute this batch file.
SELECT DISTINCT "BCP ""SELECT * FROM atable WHERE key='" + key + "' QUERYOUT ....."
FROM tablea
See BOL for BCP and maybe sp_cmdshell, etc.
April 22, 2005 at 3:26 am
Thank you very much for your help. I am going to have a look at BCP and sp+cmdshell today.
Incidentally, I need the files split as I need to send out text messages to our customers in 1,000 batches. If I text message all 147k customers at the same time and many of them have issues it may cause capacity problems for our call centre!
Thanks again for the help.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply