How to use let statement scalar output in table function

Sangeetha Priya S 210 Reputation points
2023-12-20T12:30:21.1466667+00:00

Hi,

I am using let statement where it gives tablename as a result based on some condition.

And I am trying use that value in table() function - table(tablename).

It gives me below error though I have my converted my let statement result to string using tostring and tried with toscalar function also.

table(): argument #1 must be a non-empty string literal.

Please help here to understand about table() function and how to solve this error.

Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
501 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wilko van de Velde 2,226 Reputation points
    2023-12-20T14:02:05.73+00:00

    Hi @Sangeetha Priya S ,

    I have the same error when I use a dynamic variable for the table name, for example:

    let MyTable = () {  iff( 1==1, "logsRaw","Telemetry") };
    //
    table(MyTable)
    | take 50
    

    When changing it to a constant variable, it will work:

    let MyTable = () { "Telemetry" };
    //
    table(MyTable)
    | take 50
    

    According to the documentation:
    A parameter, which isn't a scalar constant string, can't be passed as a parameter to the table() function.

    The workaround:

    let T1 = print x=1;
    let T2 = print x=2;
    let _choose = (_selector:string)
    {
        union
        (T1 | where _selector == 'T1'),
        (T2 | where _selector == 'T2')
    };
    _choose('T2')
    

    More info:
    https://video2.skills-academy.com/en-us/azure/data-explorer/kusto/query/tablefunction?pivots=azuredataexplorer#use-table-with-non-constant-parameter

    Kind Regards,

    Wilko


    Please do not forget to "Accept the answer” wherever the information provided helps you, this can be beneficial to other community members. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful