Everyone,
I have 4 vectors V1, V2, V3, V4 i want to run through a loop in an SQL query. Each vector is a list of numbers in this format ('8001', '8002', '8003') for my SQL query.
If I do a vlist <- list(c(V1, V2, V3,V4))
it give me a list
> vlist
[[1]]
[1] "'84035','84040','84037','84013','84036','84030','84026','84016','84020','84012','84019'"
[2] "'84010','84039','84029','84031','84022','84032','84044','84034','84041','84042','84043'"
query
#my code for the SQL query
vQuery <- infuse("SELECT TOP (1000) [PKID]
,[Equipment]
,[Order]
,[ActStartDate]
,[ActFinDate]
,[ActStartTime]
,[ActFinTime]
FROM [sapData].[dbo].[SAP_IW_47]
where Equipment IN ({{Vectors}})
and OrdCat = 'ZWAR'
and AcTyAct like '%TUT'
and ActStartDate BETWEEN '{{start}}' AND '{{end}}'"
, Vectors= #???, start = startdate, end = enddate)
# make it a data table
VectorQuery <- queryDataHub(vQuery)
vTable <- data.table(VectorQuery)
I am wanting to input the V1, V2, ... in the vQuery infused where Vectors= #??
. Now What I am trying to do is have a possible for loop to run the code above, and when vTable
code runs I have an output of 4 data tables V1table, V2 table, ..... Would a for-loop be best for this. I can copy and paste the entire code 4 different times, but would like to condense it down.