Description Usage Arguments Details Value Examples
This function allows you to run a query against a database, returning the results in a tibble.
1 | queryDbFromFile(server, database, filename, ...)
|
server |
The name of the DSN for the server you want to connect to |
database |
The name of the database that you want to run the query against |
filename |
A path to a file to read the query from. |
... |
Named parameters to interpolate into the query |
The query is read from the file that is passed as an argument. See queryDb if you want to pass the query as a string instead.
The connection to the server is made by odbc and uses the name of a DSN to connect to. This removes any requirement to hard code in usernames, passwords and connection strings into files.
Parameters can be used in queries by either specifying each parameter and it's value after the query parameter, or by specifying all of the parameters in a named list.
The results of the query as a tibble
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ## Not run:
queryDbFromFile("MyServerName", "MyDatabase", "file.sql")
queryDbFromFile("MyServerName",
"MyDatabase",
"file.sql",
id = 1,
date = Sys.Date())
params <- list(id = 1, date = Sys.Date())
queryDbFromFile("MyServerName",
"MyDatabase",
"file.sql",
params)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.