I’m trying to perform an update in DB2, which I started out trying with an inner join, but DB2 won’t allow that. I altered it to use a ‘where exists’ clause but now it’s telling me that main_discount in my set clause is not found (I’m assuming because it isn’t referenced until the later where exists How can I make
Tag: db2
Having weird exception using MAX(CASE WHEN) in query: DB2.iSeries.iDB2DCFunctionErrorException: ‘An unexpected exception occurred
I have the following query to put some data from rows in columns: But when I try to run it in the following code: I get this exception: “IBM.Data.DB2.iSeries.iDB2DCFunctionErrorException: ‘An unexpected exception occurred. Type: System.AccessViolationException, Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..'” I have other queries that work just
Apply column filter on summed columns in DB2
I have the following DB2 table: COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE COLUMN_TEXT DMPROD -2 CHAR () FOR BIT DATA 35 Product Code DMPTYP -2 CHAR () FOR BIT DATA 1 Period Type DMTYPE -2 CHAR () FOR BIT DATA 6 Type of Data DMVL01 3 DECIMAL 17 Value Period 1 DMVL02 3 DECIMAL 17 Value Period 2 DMVL03 3 DECIMAL 17
Selecting substring with different starting location
(I’m not sure if I’m using the correct title… please let me know if you think it should be changed to something else) Hi, I’m trying to select substring with different starting location. I have a table like this, Req: I’m trying to get a table like this: After googling around, I found CHARINDEX() might be a solution. So I
How do I get results of SQL data change statement with triggers updates applied?
I have a requirement where I need to get the immediate result of an update statement. I saw that I can do that by using the SQL data-change-statement modifiers. However, I’m not being able to get the final result after applying all associated triggers. For example, let’s say I have the following query: And let’s suppose I have a trigger
dynamic pivot SQL Query in DB2
I have table like below in DB2 where all these 3 columns are VARCHAR data type I need a dynamic PIVOT query which should select values for ABC_COL1 and ABC_COL2 in row format when FILE_NM filter is used as ABC.TXT The same query should select the values for XYZ_COL1, XYZ_COL2 and XYZ_COL3 in row format when FILE_NM filter is used
Using subquery with update SQL
I have Table 1 : EMP as below Table 2: EMP1 ID is the Key and is common in both the files. I want an Update SQL to update the amount field of Table 1 using Amount field of table 2, which gives the result as below. Result: Answer One method is a correlated subquery: You can check if the
Query to select all tables with specific last column Ibm Db2 z/os
Goal: I need to create a query to select all tables with specific last column Ibm Db2 z/os So I know I need to change my where clause for this but pretty much I want to select all the tables in my schema that have the last column as BATCH_ID. I’ve tried a length based where clause but can’t figure
How do I correct my sql query(s) so i don’t get the error “keyword UNION not expected”?
I have one (possibly two) troublesome raw sql queries in a python flask API. I think the first sql query is causing this error, but I am by no means a master at sql. The database is DB2. The full error is as follows: “[SQL0199] Keyword UNION not expected. Valid tokens: FOR USE SKIP WAIT WITH OPTIMIZE.”. Here are my
SQL query for checking whether a column with a specific value has its correspondent row with another specific value in the same column
I am not completely sure how to solve this problem. My data looks like this: And I would like to see whether L_TYPE 673 has no correct correspondent with L_TYPE = 660. I want to find out whether the column L_TYPE with the value 673 has also its correspondent 660. All the other values do not change. However, I would