cancel
Showing results for 
Search instead for 
Did you mean: 

Create statements based on the count

sravan
New Contributor II

HI ,
We have a requirement where , we hit api and get the count. Based on the count we need to create some sql statements. for example if count is 500 we to create a statements like below
select * from table where columcount between 100 and 200
select * from table where columcount between 201 and 300
select * from table where columcount between 301 and 400
select * from table where columncount between 401 and 500

Every time the count should be incremented by 100 till the total count we got from api. please help! @bojanvelevski

1 ACCEPTED SOLUTION

bojanvelevski
Valued Contributor

Hi @sravan,

You can use the following expression in a mapper in front of the SQL snap:

sl.range(100,$count,100).map((x,ind) => "SELECT * FROM TABLE WHERE COLUMNCOUNT BETWEEN " + (ind == 0 ? 100 : x + 1) + " AND " + (ind == 0 ? 200 : (x+100 < $count ? x +100: $count)))

Let me know if this helps,
Regards,
Bojan

View solution in original post

2 REPLIES 2

bojanvelevski
Valued Contributor

Hi @sravan,

You can use the following expression in a mapper in front of the SQL snap:

sl.range(100,$count,100).map((x,ind) => "SELECT * FROM TABLE WHERE COLUMNCOUNT BETWEEN " + (ind == 0 ? 100 : x + 1) + " AND " + (ind == 0 ? 200 : (x+100 < $count ? x +100: $count)))

Let me know if this helps,
Regards,
Bojan

sravan
New Contributor II

@bojanvelevski it works. Thanks!