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 2000 Forums
 SQL Server Development (2000)
 Import data from files

Author  Topic 

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-05-07 : 20:15:51
Please help me in writing a query to import the comma separated data in a text file to sqlserver 2000.
Below is the sample data from the text file.
100,1,xx,yy,20030101
100,2,21,t4,20030101
100,3,2p,01,20030101
100,1,xx,yy,20030102
100,2,21,t5,20030102
100,3,2p,01,20030102

I want the output:
100,1,xx,yy,20030101,2,21,t4,20030101,3,2p,01,20030101
100,1,xx,yy,20030102,2,21,t5,20030102,3,2p,01,20030102


dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-07 : 20:20:14
Looks like you need to import the data into a staging table before you get the output in the format you need. Check out Books On Line for BULK INSERT or the BCP command. try it out and if you have issues please post back.

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-05-08 : 13:23:26
Please help me in writing the query to insert all text files data in a directory into table..
Go to Top of Page

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-05-08 : 15:50:54
I dont have access to the on bulk insert so what is the alternative for this issue
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-08 : 16:20:40
If you are not allowed to use BCP or BULK INSERt, you can use the DTS Import/Export wizard to import the text file into a table. Then write a proc to get the data in the required format and do a final INSERT into your destination table.

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-05-09 : 09:16:05
Thanks dinkar!!!
I have to do an automation process at client places...
We had restricted permissions to use the master database..
Since DTS also needs use the File system object and bcp & bulk insert may require Xp_shell commands.I may not get permissions on master database..Please suggests !!!!
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2007-05-10 : 20:48:32
Bulk insert does not require the use of xp_CmdShell. It only requires that you have Bulk Admin role privs.

--Jeff Moden
Go to Top of Page
   

- Advertisement -