Created
March 10, 2015 22:31
-
-
Save mmparker/76cf631205ec5cb4408f to your computer and use it in GitHub Desktop.
Dynamic dates in SQL queries 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
# Pick some dynamic date - here's the start of the current month | |
start_date <- format(Sys.Date(), "%Y-%m-01") | |
# Then use paste0() to construct a query that includes it | |
# Here's an example to get all the positive QFTs this month | |
# (I have probably misremembered the field names). | |
# I'm pretty sure you have to put a # on each side of the | |
# date in order for Access to recognize it as a date. | |
test_query <- sqlQuery(tbdb, | |
paste0("SELECT person_id, test_date | |
FROM QFT_View | |
WHERE test_date >= #", | |
start_date, | |
"# AND result = 'Positive'" | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment