I don't have connection to your database, so below is a bit of pseudo-code of how I would approach this problem:
library(tidyverse)
df2 <- c('123','248')
df4 <- c("Supplier2","Supplier1","Supplier3")
input <- purrr::cross_df(list(times = df2, suppliers = df4))
#dbhandle <- odbcDriverConnect('driver={SQL Server};server=AAAA;database=TT;trusted_connection=true')
purrr::map2_chr(input$times, input$suppliers, function(x, y){
sql <- glue::glue("with tab1 as (Select * from Table1
where end_dt>=DATEADD(DAY,1,EOMONTH(getdate(),-6))
and t.id = '{x}'
and s.Supplier = '{y}'
and c.part='TT'
and t.Type = 1")
# sqlQuery(dbhandle, currTableSQL)
})
#> [1] "with tab1 as (Select * from Table1 \nwhere end_dt>=DATEADD(DAY,1,EOMONTH(getdate(),-6)) \nand t.id = '123' \nand s.Supplier = 'Supplier2' \nand c.part='TT' \nand t.Type = 1"
#> [2] "with tab1 as (Select * from Table1 \nwhere end_dt>=DATEADD(DAY,1,EOMONTH(getdate(),-6)) \nand t.id = '248' \nand s.Supplier = 'Supplier2' \nand c.part='TT' \nand t.Type = 1"
#> [3] "with tab1 as (Select * from Table1 \nwhere end_dt>=DATEADD(DAY,1,EOMONTH(getdate(),-6)) \nand t.id = '123' \nand s.Supplier = 'Supplier1' \nand c.part='TT' \nand t.Type = 1"
#> [4] "with tab1 as (Select * from Table1 \nwhere end_dt>=DATEADD(DAY,1,EOMONTH(getdate(),-6)) \nand t.id = '248' \nand s.Supplier = 'Supplier1' \nand c.part='TT' \nand t.Type = 1"
#> [5] "with tab1 as (Select * from Table1 \nwhere end_dt>=DATEADD(DAY,1,EOMONTH(getdate(),-6)) \nand t.id = '123' \nand s.Supplier = 'Supplier3' \nand c.part='TT' \nand t.Type = 1"
#> [6] "with tab1 as (Select * from Table1 \nwhere end_dt>=DATEADD(DAY,1,EOMONTH(getdate(),-6)) \nand t.id = '248' \nand s.Supplier = 'Supplier3' \nand c.part='TT' \nand t.Type = 1"
Created on 2019-06-28 by the reprex package (v0.3.0)
As you can see, it's possible to generate 6 SQL queries and what you need to do is to change purrr::map2_chr to purrr::map2_dfr and uncomment actual SQL query.