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.
Related
I would like to find out which version of DB2 we are running on our IBM i server using only SQL SELECT.
I am executing my queries via installed ODBC drivers for i Access. The places I am executing the queries are Excel-ODBC and Excel-Microsoft Query (simply because I am not a developer and therefore don't have/don't know of another place to run queries).
The following solutions do not work for me:
How to check db2 version
Get DB2 instance name using SQL
Basic reasons why I have failed to get the above solutions to work:
I do not have a SYSPROC table/have access to SYSPROC table
SYSIBMADM table does not contain a ENV_INST_INFO table.
I think these answers may be tailored to those using IBM z, but I use IBM i.
My end goal is to be able to execute a SQL SELECT and get the version of DB2 used on our server.
Try this:
SELECT RELEASE_LEVEL, TEXT_DESCRIPTION
FROM QSYS2.SOFTWARE_PRODUCT_INFO
WHERE PRODUCT_ID = '5770SS1'
AND PRODUCT_OPTION = '27'
--or this instead of the above line:
--AND LOAD_TYPE = 'CODE' AND PRODUCT_OPTION = '*BASE'
I´ve read several discussions and websites about creating a SQL query to create a table by selecting data from other table, but none of them solved my issue. I don´t know what else to do.
I am working on a SQL script to run a sequence of selects and creates do resume some data. I´ve been using this SQL queries on a SaS server using DB2 data. Now I need to migrate to Dbeaver to using other sources.
I just want to create a table by selecting some columns and data from other table, for this simple example :
"CREATE TABLE DB2XXXX.PaidResume AS
(SELECT HistoricalPaid.AccountNumber AS CONTA
FROM DB2XXX.HistPaid HistoricalPaid
WHERE HistoricalPaid.AccountNumber = 'XXXXX');
All I got it this error
Error occurred during SQL query execution
SQL Error [42601]: ILLEGAL SYMBOL "<END-OF-STATEMENT>". SOME SYMBOLS THAT MIGHT BE LEGAL ARE:. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.19.26
If I just exclude the "CREATE TABLE DB2XXXX.PaidResume AS" and run the select only, it works.
You must include WITH DATA or WITH NO DATA at the end of the SQL statement. For example:
create table u as (select a from t) with data;
See example at db<>fiddle.
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.
I am trying following query in MS Access 2010 database:
Query:
SELECT ID, Title, Priority, Workflow_Instance_Step_ID:ID
FROM Task
Error:
Error Source: Microsoft Office Access Database Engine
Error Message: Syntax error (missing operator) in query expression 'Workflow_Instance_Step_ID:ID'
I know that field "Workflow_Instance_Step_ID:ID" is giving error as it has ':' operator, but I cant change it as it it coming from share point list.
I have tried '[Workflow_Instance_Step_ID:ID]' but still its giving an error.
Please give me your suggestion on the same.
I am unable to recreate your issue, at least with a native Access table in Access 2010. I created a table named [baz] with a single text field named [foo:bar]
foo:bar
-------
this
is
a
test
and the query
SELECT [foo:bar] FROM baz;
works fine, so a field name containing a colon character does not seem to cause problems for Access SQL as such.
An ODBC linked table to a SQL Server table with the same structure does not cause problems either.
In both cases the queries were run from within Access 2010 itself.
So we might be in diagnosis mode, so lets try
SELECT * FROM Task
and then look at the FieldNames that come back.
I've looked around about this error, but everything seems to be related to permissions issues.
I have an Access 2003 database that has the following update query in it.
UPDATE dbo_vdvStockStatus
INNER JOIN [#tblReport] ON dbo_vdvStockStatus.ItemKey = [#tblReport].MatItemKey
SET [#tblReport].QtyOnHand = [#tblReport].QtyOnHand-dbo_vdvStockStatus.QtyOnHand
WHERE (((dbo_vdvStockStatus.WhseID)="Q"));
The dbo_vdvStockStatus is a view from SQLServer, and #tblReport is a local table in the Access db. Everything works for this.
So I created a copy of the query, and just changed the view to a different view.
UPDATE dbo_vdvInventoryStatus
INNER JOIN [#tblReport] ON dbo_vdvInventoryStatus.ItemKey = [#tblReport].MatItemKey
SET [#tblReport].QtyOnHand = [#tblReport].QtyOnHand-dbo_vdvInventoryStatus.QtyOnHand
WHERE (((dbo_vdvInventoryStatus.WhseBinID) like "*insp*"));
This one, however, gives me the infamous error above. I tried removing the wild card from the parameter, but it still gives me the error.
Since #tblReport is the same table (and database) I successfully update in the first query, why does it fail on the second?