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.
| Author |
Topic |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-02-20 : 01:57:12
|
| i want to read a file line by line in a STORED PROCEDUREand makes changes on some of the text beacuse of hebrew problemdoe any 1 can helpthnaksi n advancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2006-02-20 : 07:06:39
|
| I suppose you could use bcp utility, and then use -F (first row parametre) and -b (batch size parametre), to build the bcp dynamically, and read the file 1 row at a time. i.e. build bcp with @Iteration that increments, and use that for the -F parametre, and set the -b 1, which should read 1 line at a time, I THINK.... Alternatively, you could use -L last row, and set it = -F +1...You can do the same with Bulk Insert, I believe...*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2006-02-21 : 04:59:32
|
Ok, since there've been no more takers on this, I tested it out.This is a proof-of-concept - I don't think this is a good way to approach file handling, but I did it to see if it is possible.--Test file Contents:/*TestFileLine 1TestFileLine 2TestFileLine 3TestFileLine 4TestFileLine 5TestFileLine 6TestFileLine 7TestFileLine 8*/-- SQL Code:set nocount ondeclare @IncrementCounter int, @BulkInsertSQL varchar(1000), @Error int, @RowCount int, @FileLocation varchar(500)create table ##TestLineByLineInsert( FileLine varchar(8000))select @FileLocation = 'c:\TestFile.txt'select @Error = @@Error,@RowCount = @@RowCountselect @IncrementCounter = 0while (@Error = 0) and (@RowCount <> 0) begin --you may want to delete the rows so only your line is in this temp table delete from ##TestLineByLineInsert set @IncrementCounter = @IncrementCounter +1 select @BulkInsertSQL = 'Bulk insert ##TestLineByLineInsert from '''+@FileLocation+''' with (FirstRow = ' +str(@IncrementCounter)+', LastRow = '+str(@IncrementCounter)+')' exec (@BulkInsertSQL) select @Error = @@Error,@RowCount = @@RowCount select FileLine from ##TestLineByLineInsert --do you line manipulation and processing here etc.end--RESULTSFileLine TestFileLine 1FileLine TestFileLine 2FileLine TestFileLine 3FileLine TestFileLine 4FileLine TestFileLine 5FileLine TestFileLine 6FileLine TestFileLine 7FileLine TestFileLine 8FileLine ... interesting to prove it could be done, but still think you should do file manipluation from a coding language like C#, VB etc.*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-02-21 : 05:48:21
|
| i wil lthis code a shot!Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
|
|
|
|
|