SQLite loop routine to read excel and assign value from one table to another

66 Views Asked by At

I am trying to write a short SQLite routine for reading one table, compare it to another table and copy a value to that 2nd table. I am working in FME's InlineQuerier so reading the excel file is not a problem. The process flow:

Row i
    T1(Excel) - read the text in column "NameCode" and compare it to T2.levelname(MicroStation V8)

    Where T2.level_name is like T1.NameCode (i) AND T2.Category is empty or null
        T2.Category=T1.Category. [there will be hundreds of records that meet this requirement]
next i

I have over 1.4 million records that need to be categorized by their root name and want to keep the list of categories in Excel so it can be easily update. Some of these records would meet more than one test so that's why I need the 2nd condition of the cell being blank. I have the Excel spreadsheet in the order of importance. I am very much a SQL novice so help is greatly appreciated.

1

There are 1 best solutions below

0
user13597 On

Someone on the FME site was able to give me a solution. I'm including it here in case others have a similar problem.

    SELECT
    a.*,
    (
        SELECT "Category" FROM "T2"
        WHERE a."igds_level_name"
            LIKE '%'||replace("NameCode", '_', '@_')||'%' ESCAPE '@'
        ORDER BY "ReadOrder" LIMIT 1
    ) as "Category"
    FROM "T1" as a