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_Fatma
Community Manager
Community Manager

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

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group