Question : T-SQL Inport/Export data to SQL/CSV without using SSIS

Hi,
I have a situation where I'm transferring data between two MS SQL 2005 servers and one of the tasks is to retrieve data from one SQL server [S1] (it is also a Linked Server) and export it to a CSV file on a second server with SQL 2005 running [S2].
Rather simple would be to use SSIS and that is what i have been trying to use.
I have few of these SSIS packages that export data to csv file (Text Qualifier set as " !!!) in a SQL Job that runs nightly.
The problem I continuously run into is the connection to S1 cannot be established. I know that the connection is solid as when use a query in that same job as one of the steps it works. To fix this I go into the job, open the offending step, click on the "Data Sources" tab and enter a password into the Source Connection String. The reason for doing this is when I'm creating the SSIS package I choose the option to "Do not save sensitive data". Every now and then I have to either reapply the password or recreate the SSIS package and it's just a pain.

I'm thinking of using the BCP utility to do this but found some super extensive scripts when using it placed in stored procvedures which really seems like an overkill. I would rather not use a SSIS package at all and do this via SQL if at all possible. There's got to be a simple way to export data to a CSV file and in the same token to import data from a CSV file into a SQL 2005 tables.

I would appreciate specific examples on how to achieve both the import and export whatever the method. Few important things to note are that the columns are separated by a comma and all columns are within " (double quotes). This goes for data being exported to file from SQL 2005 table as well as provided in a file for import to a SQL 2005 table.

Sorry for the long post. Thanks a lot.

Answer : T-SQL Inport/Export data to SQL/CSV without using SSIS

You would have to try. You could add column headers to your csv file and try to import it.

The fastest way to get a csv file in is with BULK INSERT:

BULK INSERT pubs..publishers2 FROM 'c:\newpubs.dat'
WITH (
   DATAFILETYPE = 'char',
   FIELDTERMINATOR = ',',
   ROWTERMINATOR = '\n'
)

if you need the no headers you will need to use it with format.
Random Solutions  
 
programming4us programming4us