Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is it possible to parameterize a query in a Database Connector?
For example, say I want to run a SELECT query and have the ability to parameterize something in a WHERE clause, e.g.
SELECT time, user, volume FROM MyDB.Streams WHERE snapshot = $1...where the parameter $1 could be linked to some variable in the model, such as a Parameter.
By analogy, in python, using pyodbc I can do something like:
import pyodbc
# this is my parameter that will be inserted into the query
snapshot = 123
pyodbc.connect( [INSERT CONNECTION DETAILS HERE] )
cursor = connection.cursor()
query = "SELECT time, user, volume FROM Streams WHERE snapshot = ?"
cursor.execute(query, snapshot)
Solved! Go to Solution.