简体   繁体   English

我怎样才能写出这样的表达式

[英]How can I write the expression such that

I have this expression我有这个表情

(IIF(LTRIM(RTRIM(SUBSTR(HEADER_INFO,2,13)))='',NULL,LTRIM(RTRIM(SUBSTR(HEADER_INFO,2,13)))))

for the sample data below, but it is failing when it finds more than one D records after the H record.对于下面的示例数据,但是当它在 H 记录之后找到多个 D 记录时它会失败。

My goal is to have an expression that if it sees multiple D records after the H record, it reads those records as well, and if only one D record, it reads that record and move to the next H record.我的目标是有一个表达式,如果它在 H 记录之后看到多个 D 记录,它也会读取这些记录,如果只有一个 D 记录,它会读取该记录并移动到下一个 H 记录。

Right now, it is failing because it is expecting an H record after each D record, but there are situations as shown below where there are more than one D records after an H record.现在,它正在失败,因为它期望在每个 D 记录之后都有一个 H 记录,但是有如下所示的情况,在 H 记录之后有多个 D 记录。

HP5919274001273HWA8365C    DEFORD              DONITA         1245327121     1184950479                    6021928     0 20191001201910017        0       
D1   D00054317763400       
HP2519274011110HWA8365C    DEFORD              DONITA         1245327121     1184950479                    6021928     0 20191001201910017        0       
D1   P00054317763400       
HQ2519280005752HWA8365C    DEFORD              DONITA         1245327121     1184950479                    6022011     0 201910072019100710       0       
D1   P49348004537100       
D2   P49348015339100       
D3   P00054350049100       
HQ2519289004679HWA8365C    DEFORD              DONITA         1245327121     1184950479                    6022011     1 201910072019101610       0       
D1   P49348004537100       
D2   P49348015339100       
D3   P00054350049100       
HP2519309005224HWA8365C    DEFORD              DONITA         1245327121     1184950479                    2012699     0 201911052019110514       0       
D1   D00904667840315       
HP2519309005132HWA8365C    DEFORD              DONITA         1245327121     1184950479                    2012699     0 201911052019110514       0

Yes attached please是的,请附上

样本输出

I resolved the issue by creating variables for all the fields, so my conditions are like below (IIF(LTRIM(RTRIM(SUBSTR(HEADER_INFO,2,13)))='',v_v_ICN,LTRIM(RTRIM(SUBSTR(HEADER_INFO,2,13))))) (IIF(LTRIM(RTRIM(SUBSTR(HEADER_INFO,15,12)))='',v_v_MBR_ID,LTRIM(RTRIM(SUBSTR(HEADER_INFO,15,12)))))我通过为所有字段创建变量解决了这个问题,所以我的条件如下 (IIF(LTRIM(RTRIM(SUBSTR(HEADER_INFO,2,13)))='',v_v_ICN,LTRIM(RTRIM(SUBSTR(HEADER_INFO,2 ,13))))) (IIF(LTRIM(RTRIM(SUBSTR(HEADER_INFO,15,12)))='',v_v_MBR_ID,LTRIM(RTRIM(SUBSTR(HEADER_INFO,15,12)))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM