Quantcast
Channel: SCN: Message List - SAP Advantage Database Server
Viewing all articles
Browse latest Browse all 997

Re: Extract memo line with SQL

$
0
0

You can use the code I have posted here:

 

http://stackoverflow.com/questions/5352547/splitting-a-string-into-rows

 

DECLARE@input STRING;
DECLARE@delimiter_position INTEGER;
DECLARE@delimiter STRING;

TRY
DROPTABLE#output; CATCH ALLEND TRY;

SET@delimiter = CHAR(13)+ CHAR(10);
SET@input ='AA'+ CHAR(13)+ CHAR(10)+'CCC'+ CHAR(13)+ CHAR(10)+'D';

CREATETABLE
  
#output
(
     counter AUTOINC
  
, part CHAR(10)
);

SET@delimiter_position = POSITION(@delimiter IN@input);

WHILE@delimiter_position >0 DO

 
INSERTINTO#output (part)VALUES(LEFT(@input,@delimiter_position -1));
 
SET@input =RIGHT(@input, LENGTH(@input)-(@delimiter_position + LENGTH(@delimiter))+1);

 
SET@delimiter_position = POSITION(@delimiter IN@input);
ENDWHILE;

INSERTINTO#output(part)VALUES(LEFT(@input, LENGTH(@input)));

-- SELECT * FROM #output

SELECT partFROM#output WHERE counter = 3;

 

If your newlines only consist of CHAR(10) (Unix style) you just have to change the @delimiter variable.


Viewing all articles
Browse latest Browse all 997

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>