0

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.

qwr
  • 9,525
  • 5
  • 58
  • 102

1 Answers1

0

You can use SQL parameter markers by fetching the parameters from notebook is possible by using following code:

query = "SELECT * from members WHERE Age = ? and Salary < ? "
Age = <value>
Salary = <value>
data_df = pd.read_sql_query(query, engine, params=(Age,Salary))

Output:

enter image description here

Bhavani
  • 1,725
  • 1
  • 3
  • 6
  • This is for a python query. I am asking about a SQL query open in Azure Data Studio. – qwr Jul 25 '23 at 14:30
  • If it is in SQL, then declare variables and access them in query as mentioned in [this](https://i.imgur.com/b272oRD.png). – Bhavani Jul 25 '23 at 16:46