[英]R connecting with SQL Server
I have developed this code in SQL我在 SQL 中开发了此代码
*enter code here*
SELECT *
FROM database1
WHERE (Name LIKE '%T%') AND (City NOT LIKE '%Tokyo')
The above code in SQL gives in the answer I want in SSMS SQL 中的上述代码给出了我在 SSMS 中想要的答案
But I am using R studio where I am getting a user response in a textbox named "input$txtbx" and building the SQL statement along the same lines as the above.但我正在使用 R 工作室,我在名为“input$txtbx”的文本框中获得用户响应,并按照与上述相同的行构建 SQL 语句。
enter code here
dbcontext("SELECT * FROM database1 WHERE Name LIKE", '%input$txtbx%',";")
where in '%input$txtbx%' I want to get the value that user puts and matches with the LIKE operator in the SQL statement mentioned above for db context.在'%input$txtbx%'中,我想获取用户在上面提到的用于数据库上下文的 SQL 语句中输入并与 LIKE 运算符匹配的值。
So for an example, if user inputs letter 'z' then it should be something like this.例如,如果用户输入字母“z”,那么它应该是这样的。
enter code here
dbcontext("SELECT * FROM database1 WHERE Name LIKE", '%z%',";")
Both the code (in SSMS as well as in R Studio should yield same results) but I am getting an error saying Incorrect Syntax near 'input$txtbx'.两个代码(在 SSMS 和 R Studio 中都应该产生相同的结果)但是我收到一个错误,提示“input$txtbx”附近的语法不正确。
can somebody help me please?有人可以帮帮我吗?
Thanks in advance.提前致谢。
dbcontext(paste0("SELECT * FROM database1 WHERE Name LIKE", " '%",input$txtbx,"%'",";"))
# try again with con being the connection to the database:
dbGetQuery(con, paste0("SELECT * FROM database1 WHERE Name LIKE", " '%",input$txtbx,"%'",";"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.