azureazure-stream-analyticsstream-analytics

Nested condition for Azure Stream analytics


I have 2 questions:

  1. Does azure Stream analytics support nested conditions using the CASE statement ?
  2. I see there are 2 formats of CASE expression mentioned here- https://learn.microsoft.com/en-us/stream-analytics-query/case-azure-stream-analytics . I found examples for searched CASE here. Can anyone give example for the Simple CASE expression?

Solution

  • Sample data :

    [{
    "id": "0001",
    "type": "donut",
    "name": "Cake"
    },
    {
    "id": "0002",
    "type": "donut2",
    "name": "Cake2"
    ]
    

    Does azure Stream analytics support nested conditions using the CASE statement ?

    Based on my test, it supports nested case conditions.

    SQL:

    select jsoninput.id as id, jsoninput.type as type ,
    case when 
        ((case when  jsoninput.id = '0001' then '0' else '1' end) = '0' ) then '0'
    else  '1' end as res
    from jsoninput
    

    Output:

    enter image description here

    Can anyone give example for the Simple CASE expression?

    SQL:

    select jsoninput.id as id, jsoninput.type as type ,
    case jsoninput.id when '0001' then 'true' else 'false' end as res 
    from jsoninput
    

    Output:

    enter image description here