SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Import data from files
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqldba2k6
Posting Yak Master

176 Posts

Posted - 05/07/2007 :  20:15:51  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 05/07/2007 :  20:20:14  Show Profile  Visit dinakar's Homepage  Reply with Quote
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 - 05/08/2007 :  13:23:26  Show Profile  Reply with Quote
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 - 05/08/2007 :  15:50:54  Show Profile  Reply with Quote
I dont have access to the on bulk insert so what is the alternative for this issue
Go to Top of Page

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 05/08/2007 :  16:20:40  Show Profile  Visit dinakar's Homepage  Reply with Quote
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 - 05/09/2007 :  09:16:05  Show Profile  Reply with Quote
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

USA
649 Posts

Posted - 05/10/2007 :  20:48:32  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.1 seconds. Powered By: Snitz Forums 2000