Forum Discussion

sravan's avatar
sravan
New Contributor II
3 years ago
Solved

Create statements based on the count

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

  • 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

2 Replies

  • bojanvelevski's avatar
    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's avatar
    sravan
    New Contributor II

    @bojanvelevski it works. Thanks!