Access pass-through query to Oracle using WITH - sql

I tried to run this in TOAD and sqldeveloper is ok, but when I run in Access with passthrough query I got an error:
"pass-through query with returnsRecords property"
hereby the code
With T1 as (select * from baasa),
T2 as (select * from lalala),
T4 as (select * from babab)
select distinct T1.C11 as something, T4.C5 as somewhere, T2.C2 as what
from T1,T2,T4
Where T1.C11=T4.C5 and T1.C10=T2.C2
or in fiddle: http://sqlfiddle.com/#!4/84c06/2
can anyone help me?

Your (amended) query works fine in SQL Server 2008 R2, and it also works fine as an Access pass-through query to same. Verify that the Returns Records property of the query is set to Yes (as seen below) and try running the pass-through query again. As I said in my initial comment to your question, if it works for SQL Server then I see no reason why it shouldn't work for Oracle.

I'm pretty sure your query has a syntax error: there's no SELECT nor FROM clause before the WHERE clause...

Related

LinqPad - How to run multiple SQL statements at once

I'm new with LinqPad and I would like to run two simple SQL statements at the same time so I can see the values in two tables. If I run the following individually it works but now when I run them at the same time. I get an error "invalid character".
Select * From Table1; Select * From Table2;
I found this article that suggests this format but it's not working for me.
How to run multiple SQL queries?
BTW: I'm using the free version of LinqPad 5.00.08 at the moment.
I know this is old, but I found this in my search for the same problem. (Using a SQL Server Compact database.) The way I was able to get mine to work was to add GO after each query.
SELECT * FROM Table1;
GO
SELECT * FROM Table2;
GO
You need to use Dump function
Table1.Dump();
Table2.Dump();

MS Access SQL error with Update Query

working on linking data between a SQL Server Database and MS Access. Right now someone is manually calculating Data from a SQL Database report and entering this into Access to run other reports within Access.
I have created a pass through query to pull the relevant information into an Access Table from the SQL Database( all working nicely )
Now I need to update the existing Access Tables with Data retrieved from the SQL pass through. I have tried a number of different queries all fussing at me for various reasons. Here is an example of the latest query that will get me what I need. This works if I setup a Sandbox in SQL Server and run it MSSQL Management Studio, but will not work in access
UPDATE JT
SET JT.ContractAmt = SBD.TotalSum
FROM JobTable_TEST AS JT
INNER JOIN (
SELECT Sum( Main.amt ) as TotalSum, Main.job
FROM Main
GROUP BY Main.job
) AS SBD
ON SBD.job = JT.JobNumber
In Access the Above Generates the following error "Syntax error( missing operator) in query expression.
Updating following attempt at using SQL Passthrough to run the update Query.
I updated my Query to do this directly from a Passthrough SQL Statement as suggested and get the following error.
ODBC--call failed.
[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'TableName'.(#208)
Here is what the pass through query i used looked like.
UPDATE AccessTable
SET AccessTable.amt = SQLResult.Total
FROM TableName AS AccessTable
INNER JOIN ( SELECT SUM( SQLTableA.amt) as Total, SQLTableA.job
FROM SQLTableA
LEFT OUTER JOIN SQLTableB ON (SQLTableA.company = SQLTableB.company)
AND (SQLTableA.job = SQLTableB.job)
GROUP BY SQLTableA.job
) AS SQLResult
ON SQLResult.job = AccessTable.JobNum
hopefully that better describes where my tables are located and how my update needs to happen, and maybe someone can point out how this is wrong or if it will even work this way.
Any suggestions would be greatly appreciated
It appears your subquery, aliased as SBD, is missing a job_no column. Therefore you aren't going to be able to join on it.

Can ASP's objConn.execute handle a SQL query that uses the subquery factoring with clause?

I have a long SQL statement that's essentially:
with a as (select * from t1),
b as (select * from a, t2 where a.id=t2.id)
select * from b
This statement executes perfectly fine in my TOAD application. But, when I try to stuff the above into a string variable and run it in ASP using:
set rs = objConn.execute(strSQL)
I get the following error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e37'
[Microsoft][ODBC driver for Oracle][Oracle]ORA-00942: table or view does not exist
/Application/xxxxx/yyyyy/myfilename.asp, line 168
Line 168 is the set rs = objConn.execute(strSQL) line.
I've used these same tables to run several other queries and posting them online using the set rs = objConn.execute(strSQL) line with no problem. The only thing I can determine is different with this SQL query is the subquery factoring.
I tried wrapping the whole query up in it's own select statement like:
select * from (with a as blah blah... entire original query)
But that still throws the same error. Can I just not use set
rs = objConn.execute(strSQL)
in conjunction with subquery factoring? Is that not supported? Or is there some kind of work around? Or could it be something else entirely?
Thanks.
I'm stupid. Wrapping select * from () around the whole block does indeed work. My error was being thrown because I forgot I was trying to join into an old (rarely used anymore) table that was actually in a different schema that I wasn't connected to. I solved the problem by rewriting the query to pull some of the needed data from that obscure table to a different table that I was connected to and contained the same data I needed.
The Microsoft OLE DB Provider for ODBC Driver is very old. It was created when Oracle 7 was around and has not really been updated since. The WITH clause was added with Oracle 9.2.
I am surprised your select * from () workaround does not work. It is exactly what we are using and it is working fine for us.
Another solution is to use the Oracle Provider for OLE DB instead of the Microsoft driver. It is provided by Oracle and is updated with every Oracle release.

MS Access SQL Server DB - Query Syntax for CAST Function

I have converted an Access db (.mdb) to SQL Server. In the meantime I still need to use Access as a front end until new application forms are constructed. Can someone tell me what I might do to fix the situation where:
In Access 2007, a query such as:
SELECT *
FROM TransactionTotals
WHERE TransactionTotals.[Date]= Date()
ORDER BY TransactionTotals.EntryID DESC;
worked, however since the Date() function will not work with SQL Server, with help in a previous post the correct syntax is:
SELECT *
FROM TransactionTotals
WHERE TransactionTotals.[Date]= CAST(GETDATE() AS DATE)
ORDER BY TransactionTotals.EntryID DESC;
BUT! Although the code above will work in a direct SQL Server query (SQL Management Studio), it will be tossed out in Access with a Syntax Error response on the WHERE clause.
Can something be done in Access so I can still run my query bound forms.
I usually do exactly what you do, Access first before migration to SQL server. Access has some really weird syntax compared to server type databases especially when it comes to JOIN clauses and dates, GETDATE() only works on SQL Server, in Access, try this...
SELECT *
FROM TransactionTotals
WHERE TransactionTotals.[Date]= Format(NOW(),"General Date")
ORDER BY TransactionTotals.EntryID DESC;
Feel free to change the format of the date, with or without time.

Querying another DB while connecting to other Database in SQL

In my SQL script I am using one database(Lets assume MyDb1).
In side that script I need to query extended property of another DB (MyDb2).
I have no Idea to do this.
Please advise me.
You can use this Query :
SELECT * FROM MyDb1.DBO.TableName as tbl1,MyDb2.DBO.TableName as tbl2
WHERE tbl1.ID=tbl2.ID