|
OnMyOwn
Starting Member
2 Posts |
Posted - 2005-03-17 : 11:51:08
|
| How can I export a SQL Server table to a CSV file and have each field in my query go to individual cells in the CSV file? When it goes to the CSV file, the entire query is stuffed into cell A1 without any visible separation between what should be different fields.I am exporting file on a server with the following stored procedure:DECLARE @FileName varchar(50), @bcpCommand varchar(2000)SET @FileName = REPLACE('H:\DailyData\Jobs\eMax\ERC\ERC_appts_' +CONVERT(varchar(10),GETDATE(),1)+'.csv','/','-')SET @bcpCommand = 'bcp "SELECT ControlNum, ClientID, CandidateID, CallAttempts, LastCallDate, CallDispositionID, CallDispositionDesc, LastName, FirstName, Address1, Address2, City, State, ZIP, Country, BestPhone, Phone, HomePhone, WorkPhone, MobilePhone, Email, left(ApptDate,11) as ApptDate, right(ApptTime,7) as ApptTime, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Comments FROM [ERC3963_db].[dbo].[workSpace]" queryout "'SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P "" -c'print @bcpCommandEXECUTE master..xp_cmdshell @bcpCommandPlease help!!! |
|