I would like to get the last column data and insert into database.
This is the sample data.
================================= Yield =======================================================
S1| S2| S3| S4| S5| S6| S7| Pensoft|
.# Inspected =| 2506| 2507| 2500| 0| 2487| 2513| 2691| 2535|
.# Pass =| 2495| 2480| 2485| 0| 2487| 2513| 2691| 2503|
.# Fail =| 11| 0| 14| 0| 0| 0| 0| 26|
.# Invalid =| 0| 27| 1| 0| 0| 0| 0| 6|
.Yield =| 99.56| 98.92| 99.40| 0.00| 100.00| 100.00| 100.00| 98.73|
In the table there is "Pensoft" column. I need to capture the "Inspected" row value in Pensoft column. The "Pensoft" column is total. I can't get the value into the database it keep showing
Error converting data type varchar to numeric.
Below is my code. Is it I have missing something?
ELSE IF @ls_long_line LIKE '% S1| S2| S3| S4| S5| S6| S7| Pensoft|%'
BEGIN
SELECT @li_total_index = charindex('Pensoft',@ls_long_line) -1
END
ELSE IF CHARINDEX('.# Inspected =|' ,@ls_long_line) > 0
BEGIN
print @ls_long_line
select @li_pos = charindex('|',@ls_long_line)
--INSPECTED---
select @li_pos = charindex('|',@ls_long_line,@li_pos)
select @ls_temp = replace(ltrim(rtrim(SUBSTRING (@ls_long_line,@li_pos,len(@ls_long_line)))) ,' ','')
SELECT @ls_total_units_tested = convert(decimal(9,0),@ls_temp)
END
I get this messages when I execute it. May I know where did I did wrong and how can I change it? This is to read text file data and the value will be in 5 digit also. How can I get it on the last column data?
FileName :D:\TESTENG\DATA\BACKEND\PENTA\P0248591_NOV92020_0H47M_SERVER.TXT
.# INSPECTED =| 2506| 2507| 2500| 0| 2487| 2513| 2691| 2535|
Msg 8114, Level 16, State 5, Procedure load_PENTA, Line 320
Error converting data type varchar to numeric.