SQL Server Azure Data Studio use SQL parameters

pw9qyyiw  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(105)

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.

0g0grzrc

0g0grzrc1#

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:

相关问题