Created
October 20, 2021 22:25
-
-
Save johnmackintosh/9e4d0b63e75a6121005f8da3c4b04397 to your computer and use it in GitHub Desktop.
no nonsense interpolation of integer as part of SQL SERVER dateadd function in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ndays <- 7 | |
ndays_sql <- ndays * -1 | |
con <- DBI::dbConnect(odbc::odbc(), | |
Driver = "SQL Server", | |
Server = "SERVER", | |
Database = "TABLE", | |
Trusted_Connection = "True", | |
Port = 1433) | |
data_sql <- dbSendQuery(con,sqlInterpolate(con,"SELECT cols, that, I , want | |
FROM [server].[schema].[table1] t1 | |
LEFT JOIN [server].[schema].[table2] t2 ON t1.common_ID = t2.common_id | |
WHERE Certain_Date >= DATEADD(D,?ndays2, GETDATE()) | |
ORDER BY Certain_Date DESC", | |
ndays2 = ndays_sql)) | |
data <- dbFetch(data_sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment