sql-serverazuret-sqlazure-data-studio

Azure Data Studio use SQL parameters


Is it possible to use SQL parameter markers by specifying the parameter somewhere in Azure Data Studio?

For example, a query query.sql like

SELECT * FROM table WHERE foo = ?

and having the parameter specified somewhere outside the query when run (for example with pyodbc this would be something like pd.read_sql(query, conn, params=["param"])).

Unlike Azure Data Studio - Setting SQL variables to be used as globals, I don't need a T-SQL global variable.


Solution

  • Short answer: Azure Data Studio does not support notebook parameters for the SQL kernel. This is as of 6/21/2024 (v 1.48.1).

    A little rant

    ADS certainly leads one to hope it would support this. You can Make parameter cell in a SQL-kernel notebook, but if you try to Run with Parameters you'll get the error:

    Run with parameters is not supported for Untitled notebooks. Please save the notebook before continuing. Learn more.

    Oh, wait, that sounds promising, I'll just save the notebook and try again and...

    This notebook cannot run with parameters as the kernel is not supported. Please use the supported kernels and format. Learn more.

    The learn more link does have a little callout that, if you read carefully, implies by omission that SQL kernel does not support notebook parameters.

    It feels very limiting, and frustrating that it took me so much fiddling to figure out that it's not supported.