0

How can I read the first row of a text file (comma separated) and use that as the field names of a new table I want to create in SQL Server?

The field names can all be varchar.

Thanks all

UPDTAE

Please note I would like to do this using T-SQL or any other way (sqlcmd etc). I do not want to use the wizard.

2 Answers 2

3

Use the import data wizard (right-click database/Tasks/Import Data...). Select flat file as your Data Source, and check the checkbox "Column names in the first data row".

Sign up to request clarification or add additional context in comments.

3 Comments

I want to do this in an automated way, sorry I should of stated this.
And since you can save this a sn SSIS package and schedule it as a job, it is the best way to get an automated process.
Some of my clients may not be using SSIS and I need this coupled with the rest of my script which exports data back out as a text file.
1

Have you tried to use OPENROWSET?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.