| Author |
Topic |
|
PHenry
Starting Member
10 Posts |
Posted - 2012-03-06 : 11:18:19
|
| Hello,Ive been struggling the past couple of weeks because I'm trying to import data from a text file into an SQL database which isnt comma delimited. I cant find any examples on the net and wondered if anyone on here could help?Please see screenprint of the text file here: [url]http://stackoverflow.com/questions/9443061/import-text-file-into-sql-database[/url]I want to find a way of getting the data out and inserting it into an SQL database. For example, I want to get the programmed and mean times out of the text file and into the database.Thank you |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
PHenry
Starting Member
10 Posts |
Posted - 2012-03-06 : 13:07:17
|
Hello Brett,Sorry to hear you cannot access the image, ive tried it and seems fine.The data isnt fixed width however the values have lots of spaces in between each other and are spread across several rows. Is there an alternative way i could show you the screen print of the text file?Many Thanks,quote: Originally posted by X002548 well, this image link is broken to me...Is it fixed width data?You can bcp or bulk insert it into a single column table and use substring to break it upOr you can use a format file and bcp or bulk insert it in to a corresponding tableIn EITHER case, I would make all of the column(s) datatype varchar until you can perform an audit of the staged tableBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
|
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
PHenry
Starting Member
10 Posts |
Posted - 2012-03-06 : 14:07:04
|
Each text file is like the below:I'm finding it difficult since its all across different rows. Looks like the post has removed the formatting i did belowJOB COMPLETION ORDER ORDER Nr 123456 Q.ty Ordered 1000CUSTOMER Pet Warehouse Q.ty done 1000Product 157855544 ITEM 5699 SHIFT Nr. 1----------------------------------------------------------------------PROGRAMMED MEAN 300 min Job TIME 377 sec 185 Setting TIME 180 1009 In Manufacture 1153 ----------------------------------------------------------------------JOB START TIME 30-06-09_21:32:37 JOB FINISH TIME 01-07-09_05:35:04 TIME IN MANUAL 0:43:?? AVERAGE CYCLE TIME 434 secAVERAGE TURN AROUND TIME 187 secquote: Originally posted by X002548 So the data is space delimited?if that's the case you can bcp/bulk insert the data to a table that matches the number of columns of data you haveDO you have a layout?If not you can bcp/bulk import into a single column tableBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
![]() ![]() ![]() ![]() |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-03-06 : 14:18:40
|
You need to use [ code] ...posted data [ /code] tags without the spaceHit reply and you will see thisJOB COMPLETION ORDER ORDER Nr 123456 Q.ty Ordered 1000CUSTOMER Pet Warehouse Q.ty done 1000Product 157855544 ITEM 5699 SHIFT Nr. 1----------------------------------------------------------------------PROGRAMMED MEAN 300 min Job TIME 377 sec 185 Setting TIME 180 1009 In Manufacture 1153 ----------------------------------------------------------------------JOB START TIME 30-06-09_21:32:37 JOB FINISH TIME 01-07-09_05:35:04 TIME IN MANUAL 0:43:?? AVERAGE CYCLE TIME 434 secAVERAGE TURN AROUND TIME 187 sec Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
PHenry
Starting Member
10 Posts |
Posted - 2012-03-06 : 14:26:00
|
Im wanting to extract specific pieces such as the programmed and mean times, Time in manual, Average Cycle Time, etc and then insert them into a database. I just want the values, not the text.Thanks,quote: Originally posted by X002548 You need to use [ code] ...posted data [ /code] tags without the spaceHit reply and you will see thisJOB COMPLETION ORDER ORDER Nr 123456 Q.ty Ordered 1000CUSTOMER Pet Warehouse Q.ty done 1000Product 157855544 ITEM 5699 SHIFT Nr. 1----------------------------------------------------------------------PROGRAMMED MEAN 300 min Job TIME 377 sec 185 Setting TIME 180 1009 In Manufacture 1153 ----------------------------------------------------------------------JOB START TIME 30-06-09_21:32:37 JOB FINISH TIME 01-07-09_05:35:04 TIME IN MANUAL 0:43:?? AVERAGE CYCLE TIME 434 secAVERAGE TURN AROUND TIME 187 sec Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
|
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-03-06 : 14:58:46
|
Well, let's ASSUME you read my other link and you have the text file into a table..you would then need to grab the rows you want to find, and then ENJOY the task of parsing it all out..Here is how you can find the rowsSELECT * FROM (SELECT 'JOB COMPLETION ORDER' AS DATA_ROW UNION ALLSELECT ' ' AS DATA_ROW UNION ALLSELECT 'ORDER Nr 123456 Q.ty Ordered 1000' AS DATA_ROW UNION ALLSELECT 'CUSTOMER Pet Warehouse Q.ty done 1000' AS DATA_ROW UNION ALLSELECT 'Product 157855544 ITEM 5699 SHIFT Nr. 1' AS DATA_ROW UNION ALLSELECT '----------------------------------------------------------------------' AS DATA_ROW UNION ALLSELECT 'PROGRAMMED MEAN' AS DATA_ROW UNION ALLSELECT ' 300 min Job TIME 377 sec' AS DATA_ROW UNION ALLSELECT ' 185 Setting TIME 180 ' AS DATA_ROW UNION ALLSELECT ' 1009 In Manufacture 1153 ' AS DATA_ROW UNION ALLSELECT '----------------------------------------------------------------------' AS DATA_ROW UNION ALLSELECT 'JOB START TIME 30-06-09_21:32:37 JOB FINISH TIME 01-07-09_05:35:04' AS DATA_ROW UNION ALLSELECT ' TIME IN MANUAL 0:43:?? ' AS DATA_ROW UNION ALLSELECT ' AVERAGE CYCLE TIME 434 sec' AS DATA_ROW UNION ALLSELECT 'AVERAGE TURN AROUND TIME 187 sec' AS DATA_ROW ) AS XXX WHERE CHARINDEX('Job TIME', DATA_ROW) <> 0 OR CHARINDEX('Setting TIME ', DATA_ROW) <> 0 OR CHARINDEX('In Manufacture', DATA_ROW) <> 0Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
|