How can I set multiple variables inside a KQL iff statement?

Tyler 1 Reputation point
2022-09-03T05:38:58.103+00:00

I have an SQL statement like this:

if @stopDate is null  
begin  
  set @stopDate=dateadd(day,-1,convert(date,getdate()))  
  set @startDate=dateadd(day,1,dateadd(month,-1,@stopDate))  
end  

How can I convert this to KQL? I can set one variable fine, but I'm not sure how to do two.

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.
485 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Maxim Sergeev 6,566 Reputation points Microsoft Employee
    2022-09-03T06:10:11.967+00:00

  2. ShaikMaheer-MSFT 37,971 Reputation points Microsoft Employee
    2022-09-13T08:26:48.587+00:00

    Hi @Tyler ,

    Thank you for posting query in Microsoft Q&A Platform.

    You can consider writing code as below in this case.

    let stopDate = iif(testBool, dateadd(...), <something else>);  
    let startDate = iif(testBool, dateadd(...), <something else>);  
    

    Hope this helps. Please let me know if any further queries.

    -------------

    Please consider hitting Accept Answer button. Accepted answers help community as well.


  3. User794653 0 Reputation points
    2024-03-01T14:25:28.8+00:00

    Hello,
    You can use one of the following:

    datatable(name:string, Category:string, Age:int)["Alice", "Reader", 30,
    												"John","Reader", 10 ,
                                                    "Bob","Author", 70
    												]
    // two values
    | extend AgeCategory = iif(Age > 18, "Adulte","Child")
    | extend HasDrivingLicense = iif(Age > 18, true, false)
    // multi set
    | extend bag = iif(Age > 18,
                            bag_pack("Independant", true, "AgeCategory", "Adulte",  "HasDrivingLicense", true),
                            bag_pack("Independant", false, "AgeCategory", "Child",  "HasDrivingLicense", false)
                        )
    | evaluate bag_unpack(bag) : (Independant:bool, AgeCategory:string, HasDrivingLicense:bool)
    
    
    0 comments No comments