Skip to content

Tag: db2

Update in DB2 using where exists instead of join

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 referen…

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 DECIM…

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 …

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 F…

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