SQL Query to Get DB2 Version on IBM i - sql

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'

Related

SQL Server FullTextSearch doesn't work properly for German

We have two SQL Servers and on both of them FTS is enabled and should be configured the same way. Both run with the same server version. The SQL Server we have problems with runs in Azure.
I also have checked the wordbreaker language versions with the following statement. Both have the version 14.0.4763.1000 installed for German (1031).
EXEC sp_help_fulltext_system_components 'wordbreaker'
On one server, we do not get results properly, even though the word we are searching for exists in the table. With the following query we don't get any results:
SELECT *
FROM vsTst vsTst
WHERE CONTAINS(vsTst.Content, 'FORMSOF(INFLECTIONAL, Einzelunternehmen) OR "Einzelunternehmen*"', LANGUAGE 1031)
But with the keyword "Einzelunternehm" instead of "Einzelunternehmen" we get the results we are looking for:
SELECT *
FROM vsTst vsTst
WHERE CONTAINS(vsTst.Content, 'FORMSOF(INFLECTIONAL, Einzelunternehmen) OR "Einzelunternehm*"', LANGUAGE 1031)
We have absolutely no clue what the issue is. Does anybody have the same problem or have any idea what we have done wrong?
Thx

Oracle CTE failing in one computer

I have queries created in Microsoft Query to run in Excel with VBA.
They work in different computers but there's one computer where it doesn't work.
In that computer the queries still work except the ones that use CTEs.
A normal query like the following works:
SELECT
TBL.COL
FROM
DB.TBL TBL;
But when it has a subquery (CTE) like the following:
WITH
SUBQUERY AS (
SELECT
TBL.COL
FROM
DB.TBL TBL
)
SELECT
SUBQUERY.COL
FROM
SUBQUERY;
It runs but doesn't retrieve any data.
It doesn't even show the column name like it would if it worked but had 0 records returned.
The query shows the warning message:
SQL Query can't be represented graphically. Continue anyway?
Which is normal and shows in any computer, but it also shows another warning message after:
SQL statement executed successfully.
Which only appears in that computer when it doesn't work.
I need to be able to use them for the queries that I have made.
Using temporary tables would maybe work but I don't have the permissions required to try.
I tried using inline views but they duplicate the data.
I have queries created in Microsoft Query to run in Excel with VBA.
... but there's one computer where it doesn't work.
Common table expressions (i.e., the WITH clause) were not introduced until release 9 of the database. Since ODBC is involved (Microsoft Query), the most likely reason for your situation is that the computer that does not work has an out-dated (pre-release 9) version of the Oracle Client installed.
Compare the Oracle Client installations between a client computer that works and one that does not, to find whether this is the case. If it is, upgrade the Oracle Client on the problematic machine.
I think you can use...
SELECT
SUBQUERY.COL
FROM
(
SELECT
TBL.COL AS COL --or (TBL.COL COL) or ( COL ) #if not duplicate with any
FROM
DB.TBL TBL
) SUBQUERY;

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.

SQL Query in Hibernate

I'm carrying out a SQL query which looks like:
SELECT thi.*
FROM track_history_items thi
JOIN artists art
ON thi.artist_id = art.id
WHERE thi.type = TrackBroadcast
Group By art.name
ORDER thi.created_at DESC
This works fine when I run it directly on my database from MySql Workbench, but when I run in through Hibernate, I get a No Dialect mapping for JDBC type: -1 error.
Anyone have any ideas what could be causing it?
Probably one or more of the columns in the query is not supported by the mysql dialect... try expanding the * and add one column at a time until you find the offending one.
Then it is just a matter of deciding whether you need that column or not.