About SQL Query

Hello, I have a question about SQL.
I want to print my SQL outputs to Excel using the values in my Output Excel(year,colour,gearbox_types)




Output.xlsx (9.2 KB)

@muhammet.sezer2,

Use Write Range activity to write Data Table output you would receive from Execute Query activity.

Thanks,
Ashok :slight_smile:

It will read each row, write it to the query one by one, and then write it. How can I do this?

@muhammet.sezer2,

In that case use Append Range activity. This will write the new data below the last row.

Thanks,
Ashok :slight_smile:

For example: select * from ARBOR.TMP_CBU_CAR
where YEAR in (‘1.01.2021’)
and COLOR in (‘Orange’)
then
select * from ARBOR.TMP_CBU_CAR
where YEAR in (‘1.01.2008’)
and COLOUR in (‘White’)
and GEARBOX_TYPES in (‘Automatic’)

How can I update the query?

@muhammet.sezer2,

Do you mean these ‘White’, ‘Automatic’, ‘1.01.2008’ you want to make it dynamic?

Yes,it is dynamic.
image
In the query, first the 3rd line will be updated and the result will be written to d3 and e3. Then a4, b4 and c4 will be updated in the query respectively and written to d4 and e4. And this will continue until the end of the line.

@muhammet.sezer2,

Follow these steps:

  1. Read Range to Read the rows from second row as you have headers on it. This will return you DataTable variable for example dtInput
  2. Use For Each Row in data table
  3. in For each use assign activity like this:
"select * from ARBOR.TMP_CBU_CAR
where YEAR in (‘"+CurrentRow.Item("YEAR").ToString+"’)
and COLOUR in (‘"+CurrentRow.Item("COLOUR").ToString+"’)
and GEARBOX_TYPES in (‘"+CurrentRow.Item("GEARBOX").ToString+"’)"

Sample workflow:

Workflow2.xaml (9.3 KB)

Thanks,
Ashok :slight_smile:



it gives error

@muhammet.sezer2

looks like single quotes are wrong…can you try this

"select * from ARBOR.TMP_CBU_CAR
where YEAR in ('"+CurrentRow.Item("YEAR").ToString+"')
and COLOUR in ('"+CurrentRow.Item("COLOUR").ToString+"')
and GEARBOX_TYPES in ('"+CurrentRow.Item("GEARBOX").ToString+"')"

cheers

@muhammet.sezer2

can you please print this value and check how it looks…we can format accordingly

use a log message with CurrentRow.Item("YEAR").ToString

cheers

1 Like

@muhammet.sezer2,

It’s a data issue. Check if your data for month is correctly passed.

Thanks,
Ashok :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.