db2

Recursive query in DB2 to get all items in the chain

佐手、 提交于 2019-12-09 01:39:39
问题 I have to retrieve all clients linked via loans by giving only one as input. Example I have a table data as TABLEA LOAN_ID CLIENT_ID 1 7 1 8 2 7 4 8 4 9 4 10 5 9 5 11 13 2 14 3 If I have given only input as CLIENT_ID=7 then the query has to select all the columns from above table except last two column because client_id 7 has 1,2 LOAN_ID and in 1 the CLIENT_ID 8 has loan_id=4 and in this loan CLIENT_id 9 has again 5 as loan_id. can we write a sql query for this without stored procedure in DB2

Datatype conversion in IBM DB2: BIGINT to VARCHAR

[亡魂溺海] 提交于 2019-12-08 21:53:08
问题 I'm writing a query to do some stuff. But its not working the way I want it to: select CORR_ID from TABLE1 where CORR_ID not in (select id from TABLE2) The problem is, TABLE2.id is a long, while TABLE1.CORR_ID is a string. So how can I make it work? PS: I'm using IBM UDB. 回答1: Okay, I found a method: select CORR_ID from TABLE1 where CORR_ID not in (select CAST( CAST(id AS CHAR(50)) AS VARCHAR(50) ) from TABLE2) This is pretty intriguing: You can't cast a BIGINT to VARCHAR, but: you can cast a

MS SQL Server 2008 “with (nolock)” equivalent for IBM DB2 9.7

六月ゝ 毕业季﹏ 提交于 2019-12-08 19:13:59
问题 In MS SQL Server 2008 you can write like this: FROM EMPLOYEE as A with (nolock) Is there an equivalent syntax for DB2 9.7? Thanks 回答1: DB2: Uncomitted Read = WITH UR SELECT * FROM whatevertable WITH UR 来源: https://stackoverflow.com/questions/19629299/ms-sql-server-2008-with-nolock-equivalent-for-ibm-db2-9-7

How to use NOT EXISTS with COMPOSITE KEYS in SQL for inserting data from POJO

北慕城南 提交于 2019-12-08 17:34:32
问题 I am using DB2 DBMS. Scenario 1: myTable has a composite key (key1, key2) where both key1 and key2 are foreign keys from yourTable. I want to insert new data from yourTable into myTable, but only if the key1, key2 combination does not already exist in myTable. insert into myTable(key1, key2, someData) values(x, y, z) where NOT EXISTS (want to check if composite key is not already present) Scenario 2: I put data into a java object from yourTable with properties data1, data2, and data. I want

IBM Db2 net driver SQL error. Not finding table name?

半腔热情 提交于 2019-12-08 16:45:58
问题 from this query: select * from table I get the following error messages: Error: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=webuser.table, DRIVER=4.8.87 SQLState: 42704 ErrorCode: -204 Error: DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-204;42704;webuser.table, DRIVER=4.8.87 SQLState: 56098 ErrorCode: -727 Any suggestions for how to investigate the problem is much appreciated. 回答1: At first glance, it seems that DB2 is not finding that table name under the webuser schema

convert rows into column in db2

纵饮孤独 提交于 2019-12-08 15:22:16
问题 I need the below select results to be converted into single row , Actual output: ORDER POSTCODE Quantity Value 123456 AAAAA 22.78 5 123456 AAAAA 2.93 7 Expected Output: ORDER POSTCODE AmbientQuantity Ambientvalue FVQuantity FvVAlue 123456 AAAAA 22.78 5 2.93 7 How to achieve the expected output in db2? 回答1: Following SQL will do the job: with temp as ( select ORDER, POSTCODE, QUANTITY, VALUE, rownumber() over (partition by ORDER, POSTCODE) as rownum FROM mytable2 ) select ORDER, POSTCODE, max

give the db2 a hint which index to use?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 13:26:43
问题 moin-moin, I have a join over some tables, and I want to give the db2-database a hint, which index i want her to use. I know, this may result in a slow query, but I have a production and a test database, and I want the same behaviour in both databases (even if in one db the amount of data is significantly different or what state the (index-)cache has. Is this possible (and how)? I did not find anything in the online manual, which could mean, I had the wron searching criteria. Thanks a million

From Hex Value to EBCDIC in DB2 for iSeries

纵然是瞬间 提交于 2019-12-08 13:22:30
问题 I have HEX data like this (F9F9F9F9) returned from a query. When I checked from IBM link : https://www.ibm.com/support/knowledgecenter/en/SS2MB5_14.1.0/com.ibm.xlf141.bg.doc/language_ref/asciit.html F9 = 9 and F9 = 9 Here I should get result as 9999 I jhave around 1000 hex records like this in a table. How can I convert this hex values to it corrsponding EBCDIC ? I tried like : select cast(col char(2) as codebase(37)) from table How ever, its not working. THis link is also not working: I'm

Invalid data conversion: Parameter instance 50.0/100 is invalid for the requested conversion. ERRORCODE=-4461, SQLSTATE=42815

久未见 提交于 2019-12-08 13:03:28
String expression = CHEMICAL_REORDERPOINT + "*" + searchRequest.getReorderPercentage() + "/100)"; Before : String expression = CHEMICAL_REORDERPOINT + "*" + searchRequest.getReorderPercentage() + "/100)"; searchRequest.getReorderPercentage() comes dynamically from browser after submit value. Lets take value for searchRequest.getReorderPercentage() = 50 so String expression = CHEMICAL_REORDERPOINT*50/100; This is getting populated in a prepared statement of JDBC in my application, so to maintain the prepare statement rule i have used in below way: After : String expression = CHEMICAL

What is best tool to compare two different Database ,the first database is Ms Sql and another is DB2

↘锁芯ラ 提交于 2019-12-08 12:44:25
问题 I have two database , First Db is Microsoft SqlServer (version 2008 R2) and second database is DB2 i need a tool for comparing schema and tables in both ot them ? is every body have idea or solution ? 回答1: I think IBM Data Studio can do that. I don't know if it's the best tool, as you didn't say how you'd define "best". 回答2: I Found DB SOLO 4.2. Software on site : http://www.dbsolo.com/help/compare.html and i checked it . thanks your time 回答3: Try using the Toad or else you can also use SQL