Hello everyone!
I am learning how to use the Table Transformer SQL feature. I see "WHILE" in a list of available keywords, but I can't find any of its usages, only this link. Could someone please give me an example of how to apply it correctly?
My use case
I have a table with numbers. OrderedStuff can be integer or string, other columns are float. OrderedStuff has multiple rows with same index and it should be this way.
OrderedStuff | Val1 | Val2 | Val3 | ...
15 | 1.23 | 5454.65 | 34
15 | 2324 | 123.6 | 56.9
14 | 23.565 | 43242.3 | 87
13 | 87.5 | 13.67 | 56
13 |18.5 | 12.43 | 54
...
I would like to create a separate column with ValX for each OrderedStuff.
Result I would like to have
Val1 15| Val2 15 | Val3 15| Val1 14| Val2 14 | Val3 14| Val1 13 | Val2 13 | Val313
1.23 | 5454.65 | 34 | 23.565 | 43242.3 | 87 | 87.5 | 13.67 | 56
2324 | 123.6 | 56.9 | |18.5 | 12.43 | 54
...
The empty space usually says "false" in my case which is okay.
Right now I'm doing it this way
SELECT
CASE WHEN 'OrderedStuff' = 15 THEN 'Val1' END AS 'Val1 15',
CASE WHEN 'OrderedStuff' = 15 THEN 'Val2' END AS 'Val2 15'
CASE WHEN 'OrderedStuff' = 15 THEN 'Val3' END AS 'Val3 15',
CASE WHEN 'OrderedStuff' = 14 THEN 'Val1' END AS 'Val1 14',
CASE WHEN 'OrderedStuff' = 14 THEN 'Val2' END AS 'Val2 14',
CASE WHEN 'OrderedStuff' = 14 THEN 'Val3' END AS 'Val2 14',
CASE WHEN 'OrderedStuff' = 13 THEN 'Val1' END AS 'Val1 13',
CASE WHEN 'OrderedStuff' = 13 THEN 'Val2' END AS 'Val2 13'
CASE WHEN 'OrderedStuff' = 13 THEN 'Val3' END AS 'Val3 13'
FROM T1
The problem is: I need to write a general script, that would work with any integer number of OrderedStuff and would create separate columns for each 'ValX integer number'.
I imagine a solution like
WHILE i from 0 to LENGTH( OrderedStuff )
DO {
WHILE X from 0 to LENGTH( ValX )
DO {
SELECT
CASE WHEN 'OrderedStuff' = i THEN 'ValX' END AS 'ValuesX i'
FROM T1
}}
Is it possible to do it in Table Transformer?