Skip to content
Advertisement

Tag: db2

Retrieve last record in a group based on string – DB2

I have a table with transactional data in a DB2 database that I want to retrieve the last record, per location and product. The date is unfortunately stored as a YYYYMMDD string. There is not a transaction id or similar field I can key in on. There is no primary key. DATE LOCATION PRODUCT QTY 20210105 A P1 4 20210106

How perform a transaction in ibm db2

I’m working with an accounts table I tried to run this sql which transfer funds from one account to another. I got this error savepoint “FIRST_SAVEPOINT” does not exist or is invalid in this context.. SQLCODE=8080, SQLSTATE=3B001, DRIVER=3.69.56 What could i do ? I’m using IBM Data Studio 4.1.2 and IBM DB2 Express-C Thanks for all the help Answer In

Cannot use a CTE in a scalar subquery in Db2

I’m trying to use a CTE in a DB2 LUW v11.5.4.0 scalar subquery, but this doesn’t work: I’m getting this error: SQL Error [42601]: An unexpected token “AS” was found following “1 IN ( WITH t (x)”. Expected tokens may include: “JOIN”.. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.26.14 Can this be done? Is there a workaround? (This is similar but not the same

Replace values for each ID and each month in IBM DB2 SQL?

I have about several milion record table in IBM DB2 with 4 columns: yeas, month, personal_number (2 milion), personal_id. The key is that I want to get same table from this one, but I want to fill in personal_id column value from last month (in all previous months). Point is to get 1-1: 1 personal_id relate to 1 personal_number. Here

How to use a sub-query to pick out corresponding value for another minimum

I’m trying to find a name of a Community Area that corresponds to the minimum safety score in another column. Current code is resulting table What I want is a table that has COMMUNITY_AREA_NAME defined as WASHINGTON PARK and SAFETY SCORE defined as 1. COMMUNITY_AREA_NAME SAFETY_SCORE WASHINGTON PARK 1 Dataset is taken from here: https://data.cityofchicago.org/Education/Chicago-Public-Schools-Progress-Report-Cards-2011-/9xs2-f89t Any help is appreciated. Answer

How to create generated columns in DB2/400

I wanna create a virtual column which concatenates two columns to 1. My attempt was: This should work according to the docs. ( https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/db2/rbafzpdf.pdf?view=kc ) (page 851). Has anyone an idea how to get this done? Thanks in advance. edit: I doublechecked it. This doesn’t work either. Answer Always give your Db2 version (or in this case , the version

Advertisement