Hi,

I'm getting data from a system formated as a print out

Headers on every page,
Debitornumber on every block and some lines with data.

What I want to do is:
Import the rawdata into a sql table with one column (done)

Use a stored procedure to walk through the lines,
look for a specific line with the debitor number and
the number of lines.

So I started with
************
USE Northwind
GO


-- Declare the variables to be used.
DECLARE @debitor INT
DECLARE @Anzahl_der_Posten INT
DECLARE @Buchungskreis INT
DECLARE @ST Char(7)
DECLARE @Zuordnung Char(7)
DECLARE @Belegnr Char(10)
DECLARE @Art Char(3)
DECLARE @Belegdatum Char(10)
DECLARE @S Char(1)
DECLARE @Fae Char(2)
DECLARE @Betr_HW Char(18)
DECLARE @HW Char(5)
DECLARE @Ausgl_bel Char(10)
DECLARE @Text Char(50)
DECLARE @zeile Char(146)
DECLARE @zeilenzaehler INT
declare @sql nvarchar(4000)
declare @tn sysname
DECLARE @Suchtext Char(50)

-- Initialize the variable.
SET @debitor = 0
SET @Anzahl_der_Posten = 0
SET @Buchungskreis = 0
SET @ST = ''
SET @Zuordnung = ''
SET @Belegnr = ''
SET @Art = ''
SET @Belegdatum = ''
SET @S = ''
SET @Fae = ''
SET @Betr_HW = ''
SET @HW = ''
SET @Ausgl_bel = ''
SET @Text = ''
SET @zeile = ''
SET @zeilenzaehler = 0
SET @Suchtext = ''

DECLARE ibiza_cursor CURSOR FOR

SELECT
col001

FROM [ibiza]

OPEN ibiza_cursor

--fetch ibiza_cursor into @tn
fetch ibiza_cursor into @zeile

--FETCH NEXT FROM ibiza_cursor --into @zeile

WHILE (@@FETCH_STATUS = 0) and @zeilenzaehler <= 20
BEGIN
-- while @debitor = ''

set @debitor =
case when left(@zeile,8) = ' Debitor'
then substring (@zeile,27,9)
else ''
end
set @Anzahl_der_Posten =
case when substring(@zeile,98,17) = 'Anzahl der Posten'
then substring (@zeile,120,4)
else ''
end
--Print @debitor + @Anzahl_der_Posten
********************

So I can look for the text string "Debitor" and can read
the number.

Also I can look for "Anzahl der Posten" (count of bookings)
which gives me a new loop-counter.

But somehow I'm lost on the way and wondering if there
is somebody out there which went through some similiar
problem solving and is willing to share that knowledge.


**********************************
Here is some raw data:

Debitor 315016349 Datum 29.01.2007 Uhrzeit 17:20:09

Buchungskreis 315 Anzahl der Posten 24
--------------------------------------------------------------------------------------------------------------------------------------------------
| St|Zuordnung |Belegnr |Art|Belegdatum|S|Fä| Betr. in HW|HWähr|Ausgl.bel.|Text |
--------------------------------------------------------------------------------------------------------------------------------------------------
| |315F00001008 |650281 |SK |12.12.2006| | | 179,00 |EUR |5102214 |*17.12.2006/SUZUKI/AKIHIRO/PERS. / |
| |315F00001008 |650281 |SK |12.12.2006| | | 179,00-|EUR |5102214 |*17.12.2006/SUZUKI/AKIHIRO/PERS. / |


thanks a lot for any hints

Michael