Skip to content

Instantly share code, notes, and snippets.

View BirgittaHauser's full-sized avatar

Birgitta Hauser BirgittaHauser

View GitHub Profile
@BirgittaHauser
BirgittaHauser / gist:86e18528b01c9452392e4d10043fe9d9
Created November 3, 2019 10:25
Locate_In_String - Determine the last occurence of a character or a set of characters
-- With the scalar function LOCATE_IN_STRING it is possible to search a string backwards
-- IBM Documentation: If the value of the 3rd parameter (START) is less than zero, the search begins at
-- CHARACTER_LENGTH(source-string) + start + 1 and continues for each position to the
-- beginning of the string
-- Example, determine the last '/' in an IFS file name, so the file name can be determined
With x (IFSFile) as (Values('/home/Hauser/JSON/Examples/MyFile.json'),
('/MyCompany/MyFirstDirectory/My2ndDir/LastDir/Sales20191103.txt'),
('Dir01/NextDir/MySQLScript.sql'),
('MyFile.txt'),
@BirgittaHauser
BirgittaHauser / RetrievePFwithUniqueKey
Created October 31, 2019 09:23
Determine DDS described physical files containing Unique Keys
-- Determine DDS described physical files with unique Keys
Select a.*
From syspartitionIndexstat a
Where Table_Schema = 'YOURSCHEMA'
and Index_Type = 'PHYSICAL'
and UNIQUE = '0';
@BirgittaHauser
BirgittaHauser / CvtNum2Date.SQL
Created October 24, 2019 10:43
SQL Function to convert a numeric date into a real date
-- 1. CvtNumYYYYMMDD2Date User Defined Function
-- Convert a numeric date in the format YYYYMMDD into a real date
Create or Replace Function YourSchema.CvtNumYYYYMMDD2Date (
ParDateNum Dec(8, 0) )
Returns DATE
Language SQL
Specific YourSchema.CvtNumYYYYMMDD2Date
Not Deterministic
Reads SQL Data
Called on NULL Input
@BirgittaHauser
BirgittaHauser / ReadCsv.SQL
Created October 24, 2019 10:14
Read *.Csv file and split the content into rows and columns directly with SQL (on Db2 for i)
-- Read *.csv file located within the IFS directly with SQL
----------------------------------------------------------------------------------
-- Birgitta Hauser - 2019-10-25
-- 1. *.csv file located in the IFS: /home/Hauser/Employee1.csv
-- with the following content (including the column description)
-- "EMPLOYEENO","NAME","FIRSTNAME","ADDRESS","ZIPCODE","CITY","COUNTRY"
-- 10,"Meier und Sohn","","Industriestr. 3-13","80333","Muenchen","DE"
-- 20,"Bauer","Herrmann","Wald-und-Wiesen-Weg. 4","63128","Dietzenbach","DE"