Recently, I had a task to move the SQL from an SSRS report to a stored procedure so we could manage the updates easier. After digging around, I found enough pieces from various articles to create a working model. The biggest hurdle was passing in a list to filter the results. I found there was not a native array within SQL. Once I found the user-defined type and how to create on a task, the rest was easy; well maybe not easy, but do able. Since I could not post a sample using our own data files and content, I found the standard SQL test database for the IBM i. You can read the Linkedin article below for the results. Object . . . . . . . . : DEPARTMENTS_NEEDED Type . . . . . . . . . : *TYPE Release . . . . . . . : COMPANY/SAMPLE/BASE Ext Dta Scan Object ------------------ Source ---------------- Environment Release Attribute Attr Opt Version Status Library Library File Member Type ============== ========== ========== === === ======== ======== ========== ========== ========== ========== ====== PDN *NOT RES *SAME SMPBASPDN SMPBASPDN SAMPLE SMDEPRTT1 Object library group: 1 DATA OBJECTS FOR SMPLIBXXX (ALL) Source library group: 7 NON-PRD SRC FOR SMPSAMPCHG QUA *NOT RES *SAME SMPBASQUA SMPBASQUA SAMPLE SMDEPRTT1 ITG *NOT RES *SAME SMPBASITG SMPBASITG SAMPLE SMDEPRTT1 DVP DEVAPROG *SAME SQL PRM 00000000 *NOT CUR LIMAPROG LIMAPROG SAMPLE SMDEPRTT1 Pseudo Tasks . . . . . . . . . : SandBox Object text . . . . . . : Create command . . . . : ASQTYPE TYPE(LIMAPROG/DEPARTMENTS_NEEDED) SRCFILE(LIMAPROG/SAMPLE) SRCMBR(SMDEPRTT1)
--CREATE ARRAY TO USE FOR THE DEPARTMENTS FOR EMPLOYEE STORED PROC CREATE TYPE &LIB.DEPARTMENTS_NEEDED AS VARCHAR(03) ARRAY[]
IBM i SQL Stored Procedure with Array
------------------------------
David Taylor
Senior Developer
Range Resources Corporation
Fort Worth TX US
------------------------------