Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 using either BCP or any...

Author  Topic 

davidk
Starting Member

5 Posts

Posted - 2009-02-26 : 21:59:15
I have some text files which was bulk copied from database tables. I need to copy those text files into tables.

But i have problem with that, for example...

one of the file name is "file1.txt". I dont know how many columns data is there in that file. While i am inserting into the database i need to create one table before with the name "file1"(file name).

And one more thing is, how many columns the file consists of, that many columns should create in the table with the column names any thing like col1,col2,col3 with varchar(255).

Basically i want to know how many column names does the file contains, with those many columns(col1,col2...) i need to create table before "BCP in ....".
like that i have some hundred of files. like this i will get every day with some file name.

Can any one help out this one using either BCP or any other one...
Its urgent..

we dont want to use DTS or SSIS package. I need script for this

Advance thanks

Regards
David

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-26 : 22:45:42
You can't do this with just bcp. You're going to need to write some code. You could use VBScript I suppose to read the file and figure out how many field terminators there are. I'd probably just insert the whole file into a single column in a table though and then use T-SQL to parse the data with a function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -