Skip to main content
Solved

What transformers to use to extract values from a list and put in SQL statement

  • June 26, 2021
  • 1 reply
  • 18 views

I have a list which has two elements {make, model}. I can receive multiple make, model in in this list. So, I can get values like:

{make = Toyota, model =camry},{make = Toyota, model =Prius} and so on.

I need to use these values create a sql in the format -

select * from cars where (make=toyota and model = camry) or (make = toyota and model - Prius);

 

How do I achieve this in FME? I dont know the no. of values that I will get in the list. Please advise, I am very new to FME

Best answer by hkingsbury

Theres a few ways you could do this, i'm not very knowledgeable with SQL - someone with more SQL knowledge will probably be able to give a better solution.

 

The approach i'd take would be to build the WHERE clause in FME and then pass it to the SQL Executer (assuming that what you're using). To do this, you need to explode the list. You'll end up with one feature for each element in the list, each will have the make and model attributes.

 

Then, using a StringConcatenator you can build part of your where clause, so you'll have on feature with "(make=toyota and model=camry)" and another with "(make=toyota and model=Prius)" and so on. You can now build another list with this attribute. Then use a ListConcatenator with the value "OR" and you'll end up with "(make=toyota and model=camry) OR (make=toyota and model=Prius) OR..."

 

Now you can place this into you SQL Executer - "select * from cars where @Value(where_statement)"

View original
Did this help you find an answer to your question?

1 reply

hkingsbury
Celebrity
Forum|alt.badge.img+53
  • Celebrity
  • Best Answer
  • June 27, 2021

Theres a few ways you could do this, i'm not very knowledgeable with SQL - someone with more SQL knowledge will probably be able to give a better solution.

 

The approach i'd take would be to build the WHERE clause in FME and then pass it to the SQL Executer (assuming that what you're using). To do this, you need to explode the list. You'll end up with one feature for each element in the list, each will have the make and model attributes.

 

Then, using a StringConcatenator you can build part of your where clause, so you'll have on feature with "(make=toyota and model=camry)" and another with "(make=toyota and model=Prius)" and so on. You can now build another list with this attribute. Then use a ListConcatenator with the value "OR" and you'll end up with "(make=toyota and model=camry) OR (make=toyota and model=Prius) OR..."

 

Now you can place this into you SQL Executer - "select * from cars where @Value(where_statement)"


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings