[英]SQL Query Error when selecting separate columns
I do not understand the error which appears in my SQL Query. 我不明白我的SQL查询中出现的错误。 If i choose in SQL
Select *
-> it is working fine and i do get the table, however if i select any of the column/s it is giving me an Error: 如果我选择在SQL中
Select *
- >它工作正常,我确实得到了表,但是如果我选择任何列/ s它会给我一个错误:
Error in
$<-.data.frame
(*tmp*
, "PROBE", value = structure(integer(0), .Label = character(0), class = "factor")) :$<-.data.frame
(*tmp*
,“PROBE”,value = structure(integer(0),。Label = character(0),class =“factor”))中的错误:):
replacement has 0 rows, data has 1427替换有0行,数据有1427
Here is my SQL code: 这是我的SQL代码:
if(input$filter == 1){
sqlOutput <- reactive({
sqlInput <- paste("select * from DWH.PROBE where DWH.PROBE.Nr =",paste0("'",d(),"'"), "And DWH.PROBE.AB BETWEEN",input$abmfrom, "AND",input$abmto,"ORDER BY Datum asc")
print(sqlInput)
dbGetQuery(con$cc, sqlInput)
})
}else{
sqlOutput <- reactive({
sqlInput <- paste("select * from DWH.PROBE where DWH.PROBE.S BETWEEN",d2(), "AND",input$sgehalt2, "And DWH.PROBE.AB BETWEEN",input$abmfrom2, "AND",input$abmto2,"ORDER BY Datum asc")
dbGetQuery(con$cc, sqlInput)
})}
And if i just add to those SQL Queries 如果我只是添加到那些SQL查询
select DWH.PROBE.S, DWH.PROBE.AB.. from DWH.PROBE
Then it comes above mentioned Error. 然后是上面提到的错误。
Additionally i need to say if i will use this SQL Query in a simple code: 此外,我需要说,如果我将在一个简单的代码中使用此SQL查询:
rs <- dbSendQuery(con, paste("select DWH.PROBE.AB, DWH.PROBE.S from DWH.PROBE where DWH.PROBE.Nr = '50' And DWH.PROBE.AB BETWEEN 40 AND 50 ORDER BY Datum asc"))
data <- fetch(rs)
It is giving me the results... 它给了我结果......
Any ideas? 有任何想法吗?
[EDIT *as my question is not a duplicate] [编辑*因为我的问题不重复]
The question posted here: http://stackoverflow.com/questions/32048072/how-to-pass-input-variable-to-sql-statement-in-r-shiny actually has nothing to do with my topic. 这里发布的问题是: http : //stackoverflow.com/questions/32048072/how-to-pass-input-variable-to-sql-statement-in-r-shiny实际上与我的主题无关。 As we can see the error in this post:
我们可以看到这篇文章中的错误:
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context.
.getReactiveEnvironment()中的错误$ currentContext():没有活动的响应上下文时不允许操作。 (You tried to do something that can only be done from inside a reactive expression or observer.)
(你试图做一些只能在反应式表达式或观察者内部完成的事情。)
I do not have a problems with passing input variable to sql statement and additionally if you can see in my SQL: The Query is in reactive context!: 我没有将输入变量传递给sql语句的问题,另外如果你可以在我的SQL中看到:查询处于被动上下文中!:
sqlOutput <- reactive({...
The solution for above question was: 上述问题的解决方案是:
to put SQL Query in reactive context which is not a thing in my case 将SQL Query置于反应式上下文中 ,这在我的案例中并非如此
[EDIT 2] -> bits related to sqlOutput()
[编辑2] - >与
sqlOutput()
相关的位
Here is a bit of code related to sqlOutput()
which i am using in my Shiny App (at the moment this is the only bit because i am stuck with SQL Query) 这里有一些与我在Shiny App中使用的
sqlOutput()
相关的代码(目前这是唯一的一点,因为我sqlOutput()
了SQL查询)
output$tabelle <- DT::renderDataTable({
data <- sqlOutput()
data$PROBE <- as.factor(as.character(data$PROBE))
data
}, rownames=TRUE, filter="top", class = 'cell-border stripe',
options = list(pageLength = 100, lengthMenu=c(100,200,500), columnDefs = list(list(width = '200px', targets = "_all"),list(bSortable = FALSE, targets = "_all"))))
Thanks 谢谢
Error doesn't relate to SQL statements, however, try changing your code to below: 错误与SQL语句无关,但是,请尝试将代码更改为:
sqlOutput <- reactive({
if(input$filter == 1){
sqlInput <- paste("select * from DWH.PROBE where DWH.PROBE.Nr =",paste0("'",d(),"'"), "And DWH.PROBE.AB BETWEEN",input$abmfrom, "AND",input$abmto,"ORDER BY Datum asc")
} else {
sqlInput <- paste("select * from DWH.PROBE where DWH.PROBE.S BETWEEN",d2(), "AND",input$sgehalt2, "And DWH.PROBE.AB BETWEEN",input$abmfrom2, "AND",input$abmto2,"ORDER BY Datum asc")
}
dbGetQuery(con$cc, sqlInput)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.