I am trying to use the SQL query to count the number of rows of myid in Table_1 data frame. The data frame is already present in R Environment and I retrieved it by following query.
Table_1 <- dbGetQuery(conn, "Select * FROM Patients")
.
Now to count() the number of rows of myid in Table_1, I use following query and it says
count_myid <- dbGetQuery(conn, "Select count(myid) FROM Table_1")
Invalid object name 'Table_1'[Microsoft][odbc sql server driver]
[sql server] Statement(s) could not be prepared
Whereas, I checked the above mentioned query for another Table and it works perfectly fine for another table. I spent hours on this to figure out the problem but I couldn't that what is actually wrong in this query and why its not working. I know it can be done using different functions of R. I did used dbReadTable() and all the same queries mentioned in this Question, but not working.
If I try to retrieve it directly from SQL database and not from the R Environment, then it works fine. From SQL DB, I use the following query.
count_myid <- dbGetQuery(conn, "Select count(myid) FROM MyProj.dbo.Patients")