This action might not be possible to undo. Are you sure you want to continue?
Query to Calculate the Max Value:
-- FIRST MAX -- ========== SELECT MAX(REFERRAL_AM) FROM TRCVRY_RFRL_SYMBOL ; -- SECOND MAX -- ========== SELECT MAX(REFERRAL_AM) FROM TRCVRY_RFRL_SYMBOL WHERE REFERRAL_AM < (SELECT MAX(REFERRAL_AM) FROM TRCVRY_RFRL_SYMBOL) ; -- N'TH MAX WITHOUT DUPLICATES -- =========================== SELECT REFERRAL_AM FROM TRCVRY_RFRL_SYMBOL A WHERE 1 = ( SELECT COUNT(*) FROM TRCVRY_RFRL_SYMBOL B WHERE B.REFERRAL_AM >= A.REFERRAL_AM ) ; -- N'TH MAX WITH DUPLICATES -- ======================== SELECT DISTINCT REFERRAL_AM FROM TRCVRY_RFRL_SYMBOL A WHERE 1 = ( SELECT COUNT(DISTINCT B.REFERRAL_AM) FROM TRCVRY_RFRL_SYMBOL B WHERE B.REFERRAL_AM >= A.REFERRAL_AM) ; To calculate day of week: SELECT DAYS(DATE(:WS-SQL-DT1))-(DAYS(DATE(:WS-SQL-DT1))/7) * 7 INTO :WS-DAY-OF-WEEK FROM SYSIBM.SYSDUMMY1 IF WS-DAY-OF-WEEK IS 0 - SUNDAY 1 - MONDAY 2 - TUESDAY
SYSDUMMY1 To get current timestamp SET :WS-CURRENT-TIMESTAMP To get current date SET :WS-CURRENT-DATE Usage of Value Clause SELECT VALUE(MAX(IPL_UPDATE_TS).POL_NO = INTEGER(DECIMAL(POL. CKY. To concatenate two Columns SELECT STF_FIRST_NAME || STF_LAST_NAME INTO :WS-USER-NM FROM CRS_STAFF WHERE STF_CODE = :WS-I-USER-ID .3 4 5 6 Addition of days - WEDNESDAY THURSDAY FRIDAY SATURDAY SELECT DATE(:WS-SQL-DT1) + 3 DAY INTO :WS-SQL-DT2 FROM SYSIBM. CURRENT TIMESTAMP) INTO :PROD-IPL-UPDATE-TS FROM VCLMS_PROD WHERE POL_NO = :PROD-POL-NO AND MODULE = :PROD-MODULE AND ANN_STMT_CO = :PROD-ANN-STMT-CO To compare CHAR and INTEGER POL.DPO_POL_NO . :WS-MAJOR-CLASS-CODE CRS_DED_POLICY POL . VCOVG_KEY CKY CKY.DPO_POL_NO)) = CURRENT DATE = CURRENT TIMESTAMP SELECT INTO FROM WHERE Here DPO_POL_NO is CHAR(15) and POL_NO is INTEGER.MAJOR_CLASS_CD :WS-POLICY-NUMBER .
SYSIBM.TBCREATOR B.TBNAME = <TAB NAME> B.COLNAME.UNIQUERULE SELECT FROM SYSIBM.IXNAME = B. A.NAME A.TBCREATOR = <TAB CREATOR> B. A.TBCREATOR B.CREATEDTS .A.ALTEREDTS DESC .COLSEQ.TBCREATOR = <TAB CREATOR> B.ORDERING .SYSINDEXES B WHERE AND AND AND AND AND A.B.IXCREATOR = B.UNIQUERULE = 'U' B.COLSEQ . A.B.IXCREATOR = B.IXNAME .A.B.IXNAME = B.IXCREATOR = B.SYSINDEXES B WHERE AND AND AND AND AND A.ALTEREDTS .CREATOR A.UNIQUERULE = ‘P’ To get Unique index of a table A.A. SYSIBM.SYSKEYS A.SYSCOLUMNS TBCREATOR = <TABLE CREATOR NAME> TBNAME = <TABLE NAME> KEYSEQ > 0 (OR) SELECT FROM WHERE AND AND SELECT A.NAME A.SYSINDEXES NAME CREATOR TBNAME – Index name – Index Creator – Table name .COLSEQ ORDER BY SYSIBM.CREATOR A.ORDERING.TBNAME = <TAB NAME> B.COLCOUNT .SYSKEYS A.COLNAME .IXCREATOR = B. FROM SYSIBM. To Get the Primary Keys for the given table name NAME SYSIBM.B.
CREATEDBY SELECT FROM SYSIBM.ALTEREDTS .only for Tables AND Views (0 for Alias) . SELECTAUTH "SELECT".CREATOR .TYPE .SYSTABAUTH WHERE GRANTEETYPE= 'P' AND TCREATOR= <TABLE CREATOR NAME> AND TTNAME = <TABLE NAME> ORDER BY PROGRAM To Get Table or View or Alias Details NAME "Table or Alias or View" . INSERTAUTH "INSERT".Created TS .SYSTABLES WHERE NAME = <TABLE or View or Alias Name> AND CREATOR = < TABLE or View or Alias Creator> TYPE = T (Table) or A (Alias) V (View) G (Temporary Table) COLCOUNT – NO OF COLUMNS . DELETEAUTH "DELETE" FROM SYSIBM.SYSKEYS IXNAME IXCREATOR COLNAME COLSEQ ORDERING Index name Index creator Column name Column Sequence in Index Order of Index To Get the affected program names because of a table SELECT GRANTEE "PROGRAM".TBNAME .TBCREATOR .COLCOUNT .CREATEDTS .Type of Index (1 or 2) .KEYCOLUMNS . TTNAME "TABLE NAME".Altered TS SYSIBM. UPDATEAUTH "UPDATE".TBCREATOR UNIQUERULE – = = = Table Creator P – For Primary Keys U – For Unique Indexes D – For Duplicate Indexes COLCOUNT INDEXTYPE CREATEDTS ALTEREDTS – No of Columns for that Index .
GRANTEE = 'PUBLIC' or <User id> A.DBNAME ) SELECT FROM WHERE AND AND AND To Get the Plan names which are Grant to PUBLIC or some User SELECT DISTINCT A.B.GRANTOR = <Grantor name> A.B.TYPE = 'T' A.TSNAME AND A.GRANTEE .SYSCOPY B WHERE A.DBNAME = B.B.NAME .A.B.TSNAME = B.CREATOR .A.SYSVIEWS WHERE NAME = <VIEW NAME> SEQNO – IF THE VIEW DEFINITION IS MORE THAN ONE LINE TEXT .STNAME .UPDATEAUTH .SYSPLANAUTH A .TEXT FROM SYSIBM.NAME = B.B.SYSIBM.B.CREATOR .A.CREATOR = <table creator> A.A.INSERTAUTH .SYSTABLES A A.SEQNO .VIEW DEFINITION To Get Image copied table names A.BINDAUTH .RECLENGTH – Record length – only for Tables (0 for Alias and Views) TBCREATOR – only FOR ALIAS – ACTUAL TABLE CREATOR TBNAME – only FOR ALIAS – ACTUAL TABLE NAME KEYCOLUMNS – No of Primary Keys To Get View Definition SELECT NAME .SYSTABAUTH B A.TSNAME SYSIBM.NAME .SELECTAUTH .DBNAME = <Database name> EXISTS ( SELECT 'X' FROM SYSIBM.SCREATOR .DELETEAUTH .EXECUTEAUTH FROM WHERE AND AND SYSIBM.
NAME .B.LENGTH .ALTERAUTH .TBCREATOR .SYSTABAUTH WHERE GRANTEE IN (<user id>.BTYPE .DELETEAUTH .TTNAME .UPDATEAUTH NOT IN (' ')) (B.SYSCOLUMNS B = 'ARLACRSA' = B.CREATOR AND A.TBCREATOR = B.CREATOR AND A.B.AND OR OR ((B.TBNAME LIKE ‘%BR%’ SELECT FROM WHERE A.NAME AND B.A.A.SCALE SYSIBM.DNAME SELECT . 'PUBLIC*') AND GRANTEETYPE = ' ' To Get the affected Plan names if an Index is Dropped BNAME .INDEXAUTH .COLTYPE .SELECTAUTH .NAME .A.B.A.SYSTABLES A .UPDATEAUTH SELECT FROM SYSIBM.SYSIBM.NAME WITH UR To Get List of tables Privileges granted to an Auth id DISTINCT TCREATOR .DELETEAUTH NOT IN (' '))) UPDATEAUTH = ‘Y’ – The Grantee can do UPDATE only UPDATEAUTH = ‘G’ – The Grantee can give Grant Permission for UPDATE To Get Column details for all the tables A.TBNAME .INSERTAUTH .BCREATOR .B.TYPE .INSERTAUTH NOT IN (' ')) (B.'PUBLIC'.CREATOR .
aliases. Otherwise.DCOLLID .DNAME . the authorization ID of the owner of BNAME.SYSPLANDEP This table records the dependencies of plans on tables.SYSPACKDEP WHERE BTYPE = ‘I’ AND BNAME = <Plan name> SYSIBM. To Get the affected Package names if an Index is Dropped BNAME . indexes. its database. functions. .The name of an object the plan depends on. . and stored procedures.DTYPE SELECT FROM SYSIBM.BTYPE . synonyms.If BNAME is a table space.SYSPACKDEP This table records the dependencies of packages on tables. BNAME BCREATOR BTYPE .Name of the plan. table spaces.BQUALIFIER .SYSPLANDEP WHERE BTYPE = ‘I’ AND BNAME = <Index name to be Dropped> SYSIBM. aliases. synonyms.FROM SYSIBM. and stored procedures. functions.DOWNER .DCONTOKEN .Type of object identified by BNAME: A F I O P R S T V DNAME Alias User-defined function or cast function Index Stored procedure Partitioned table space Table space Synonym Table View . views. table spaces. views. indexes. .DLOCATION .
Always contains blanks . list in hhmmss format) between the timestamps and convert . BQUALIFIER . minutes. T blank .Consistency token for the package. This is either: * The "level" as specified by the LEVEL option when the package's program was precompiled * The timestamp indicating when the package's program was precompiled. the seconds in a day. BTYPE . the authorization ID of the owner of BNAME. in an internal format. you derive the additional time (hours.Type of package: Trigger package Not a trigger package DOWNER DTYPE Calculate the Difference Between Timestamps PROBLEM: You need to compute the difference. Otherwise. * In the first part.The name of an object that a package depends on. . the name of its database. you subtract the start time from the end time. in number of seconds.Name of the package. between the specified timestamps TS1 (start time) and TS2 (end time).Type of object identified by BNAME and BQUALIFIER: A F I O P R S T V BCREATOR DLOCATION DCOLLID DNAME DCONTOKEN Alias User-defined function or cast function Index Stored procedure Partitioned table space Table space Synonym Table View . its database. .Name of the package collection.Owner of the package. SELECT (DAYS (TS2) . You then multiply the number of days by 86400.DAYS (TS1)) * 86400 * In the second part. and seconds. .BNAME .If BNAME identifies a tablespace. the authorization ID of the owner of BNAME. . deriving the number of days between the timestamps.If BNAME is a table space. SOLUTION: The SQL statement has two parts. to convert the days to the number of seconds. Otherwise.
HOURS (TIME TS1))) * 3600 Next you need to extract and convert the minutes to seconds: SELECT (MINUTE (TIME (TS2)) .1995 .DAYS (TS1)) * 86400) + ((HOUR (TIME (TS2)) . The following SQL call executes all the parts together in one statement to yield the final result: SELECT (((DAYS (TS2) .the time to the number of seconds. you add all partial results to produce the difference between the two timestamps in total number of seconds. This TIP provided by Platinum TIPS March .SECOND (TIME (TS1)) Lastly.MINUTE (TIME (TS1))) * 60) + (SECOND (TIME (TS2)) . First you need to extract and convert the hours to seconds: SELECT (HOUR (TIME (TS2)) .MINUTE (TIME (TS1))) * 60 Then you extract the remaining seconds: SELECT SECOND (TIME (TS2)) .SECOND (TIME (TS1)))) FROM <table name>.HOURS (TIME TS1))) * 3600) + ((MINUTE (TIME (TS2)) .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.