cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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?

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.