Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

How to pass variable in where clause in sql query?

I am using "Query Result to Grid" transformation component and using Advanced mode. I am trying to use a sql query which is similar to this:

select customer_id from customer where customer_name = ${customer_name}

${customer_name} = I have tried both job variable and environment variable but it says error parsing query. "Error! Please check SQL query"

2 Community Answers

Matillion Agent  

Dan D'Orazio —

Hi Rajish -

Can you try wrapping the variable expression in single-quotes?

select customer_id from customer where customer_name = '${customer_name}'

These can be tricky to troubleshoot at times. When I’m building some dynamic sql like this, I try to construct it in the warehouse first, using some static values to test with, and ensuring the results are what I expect. Copying it over to my Query Component, replacing the static bits with variables, seems to go more smoothly this way.

Let us know how this works out.

Best -

Rajish Shakya —

Thanks, Dan that worked!

Post Your Community Answer

To add an answer please login