cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass variables into query string?

sgannavaram
New Contributor III

I have two variables StartTimeStmp and EndTimeStmp, i am going to assign the Start timestamp to it based on Last Successful Job Runtime and EndTimeStamp would be current time of system.

SET StartTimeStmp = '2022-03-24 15:40:00.000';

SET EndTimeStmp = '2022-03-24 20:00:00.000';

I need to pass these two variables to Query String defined in a cell. How to pass these Values. The following is not a complete Query. Just snippet of query.

qrystr=('''

SELECT *

FROM (

SELECT 

 CI.CORPORATE_ITEM_INTEGRATION_ID , CI.CORPORATE_ITEM_CD where CI.DW_CREATE_TS < '2022-02-23 20:00:00.000'  ) ''') 

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

@Srinivas Gannavaram​ , in python:

spark.sql(f"""
SELECT
   CI.CORPORATE_ITEM_INTEGRATION_ID , 
   CI.CORPORATE_ITEM_CD 
WHERE
   CI.DW_CREATE_TS < '{my_timestamp_variable}' ;
""")

View solution in original post

2 REPLIES 2

Hubert-Dudek
Esteemed Contributor III

@Srinivas Gannavaram​ , in python:

spark.sql(f"""
SELECT
   CI.CORPORATE_ITEM_INTEGRATION_ID , 
   CI.CORPORATE_ITEM_CD 
WHERE
   CI.DW_CREATE_TS < '{my_timestamp_variable}' ;
""")

Kaniz
Community Manager
Community Manager

Hi @Srinivas Gannavaram​ , Were you able to resolve your query with the help of @Hubert Dudek​ 's code?

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!