Qlikview - вставка recno () для каждого изменения в столбце - PullRequest
0 голосов
/ 13 ноября 2018

У меня есть таблица с номерами документов и предметов. Мы интегрировали наше программное обеспечение в сторонний бухгалтерский пакет. При импорте третьему лицу не принимаются номера строк нашего документа, однако он отправляет их в бэкэнд в том же порядке.

Например:

Мое программное обеспечение:

enter image description here

Импорт в Программное обеспечение сторонних производителей (занимает только ограниченные поля, поскольку они не управляют запасами / партиями, контролируемыми партиями):

enter image description here

Моя цель - создать новый столбец во второй таблице, чтобы добавить номера строк для каждого изменения в номерах документов. Это позволит мне создать уникальный ключ, который мне нужен, чтобы связать таблицы двух баз данных.

enter image description here

1 Ответ

0 голосов
/ 13 ноября 2018

Если я правильно понимаю проблему, вам нужно начать с [Строка.№] 1 для каждого нового значения в [Док.№] и увеличьте поле [Строка.Нет.] На 1, пока [Док.№] совпадает с предыдущим рядом.Один из способов сделать это может быть следующим:

//load the table, in this example it is an inline table 
//but you would load it from another source
    table2:
    load * inline [
    Doc. No.,Description,Qty,Batch,Value
    Doc 1, Item1, 1, 10
    Doc 1, Item1, 2, 10
    Doc 1, Item1, 3, 10
    Doc 2, Item2, 1, 20
    Doc 3, Item3, 1, 30
    Doc 3, Item3, 1, 30
    Doc 3, Item3, 1, 30
    ];

//define an empty table that into which values can be "concatenateloaded"
    newTable2:
    load * inline [
    dummy
    1
    ];


//define starting values to be used in the loop
    let rownodigit = 0;
    let lastdocno = '';


//Iterate over each row in the table, and use the values to build 
//the new table row for row. If the table is large this would 
//require a significant amount of time...

FOR rowno = 0 TO noOfRows('table2')-1
    let docno = peek('Doc. No.', rowno, 'table2');
    let desc = peek('Description', rowno, 'table2');
    let qty = peek('Qty', rowno, 'table2');
    let batch = peek('Batch', rowno, 'table2');
    let value = peek('Value', rowno, 'table2');

    //determine what value the [Row. No.] field is to be given
    if docno=lastdocno then
        rownodigit = rownodigit + 1;
    else
        rownodigit = 1
    endif

    //build the table by generating a new row into the new table
    concatenate (newTable2) 
    load 
        '$(docno)' as [Doc. No.],
        '$(desc)' as [Description],
        $(qty) as [Qty],
        $(batch) as [Batch],
        $(value) as [Value],
        $(rownodigit) as [Row. No.]
    autogenerate (1)
    ;

    let lastdocno = docno; //store the value of docno into a new variable
                           //for comparison in the top of the loop in 
                           //the next iteration
NEXT rowno

drop field dummy; //this field was only needed to create the temporary table
drop table table2; //drop the orgiginal table, otherwise we would have 
                   //a lot of synthetic keys

//now fix the table and create the [Key] field
    table2:
    load *, [Doc. No.]&[Row. No.]&[Description] as Key
    resident newTable2
    where len([Doc. No.])>0 //this avoids the blank row generated 
                            //by the first dummy insert
    ;

//this was a temporary table that we generated and it should now be dropped
drop table newTable2; 
...