Search code examples
powerapps

PowerApps - How to assign a variable value from SQL View Column


I am retrieving a data from Azure SQL view called dbo.GetData. That view contains a column called IsRunning (boolean).

My aim is to assign that IsRunning to a global variable in PowerApps, if the SQL view returns no data, the PowerApps variable IsRunning should be false, otherwise it would get the database value of IsRunning from the SQL view.

Is it possible to that in PowerApps and how?


Solution

  • Your view can return multiple rows, so which of the values of the IsRunning do you want to retrieve? If the first one (or if you know that your view can only return zero or one elements), then you can use an expression like this:

    Coalesce(First('[dbo].[GetData]').IsRunning, false)
    

    If there no rows are returned by dbo.GetData, the value of First('[dbo].[GetData]').IsRunning will be Blank (equivalent to NULL in SQL Server). The Coalesce function will take the first non-blank argument, so it will default to false if your view doesn't have any data.