Hello everyone-
I am working with DB2 for z/OS and I need to create a User Defined Function. Basically, there's a bunch of SQL statements that I will be executing. Currently, in each of these locations, the SQL executes a case statement. This same case statement is in all the different locations, which is, of course, not good design. I would like to create a UDF so that this code is located in one location, versus 50 different SQL statments...
So, I need some help creating this UDF. This is what I have so far, but I'm quite sure I don't have it correct yet...
The input is a varchar(8).
The output is supposed to be a varchar(25).
Right now I have it coded as a series of IF ELSE statements, I wasn't sure if I could do a case statement in the function.
So could someone help me out with this? I need to have the above code corrected as is with the IF ELSE's or else re-written using a CASE statement if possible. I'd appreciate it!
I am working with DB2 for z/OS and I need to create a User Defined Function. Basically, there's a bunch of SQL statements that I will be executing. Currently, in each of these locations, the SQL executes a case statement. This same case statement is in all the different locations, which is, of course, not good design. I would like to create a UDF so that this code is located in one location, versus 50 different SQL statments...
So, I need some help creating this UDF. This is what I have so far, but I'm quite sure I don't have it correct yet...
The input is a varchar(8).
The output is supposed to be a varchar(25).
Right now I have it coded as a series of IF ELSE statements, I wasn't sure if I could do a case statement in the function.
Code:
CREATE FUNCTION UDF_StatusLookup( @status varchar(8))
RETURNS @retStatus string(varchar(25))
AS
BEGIN
IF @status = 'PROD' Then
@retStatus = 'Production'
ELSE
IF @status = 'PROD_ST1' Then
@retStatus = 'Production - Status 1'
ELSE
IF @status = 'PROD_ST2' Then
@retStatus = 'Production - Status 2'
ELSE
IF @status = 'TEST' Then
@retStatus = 'Test'
ELSE
IF @status = 'TEST_ST1' Then
@retStatus = 'Test - Status 1'
ELSE
IF @status = 'TEST_ST2' Then
@retStatus = 'Test - Status 2'
END
So could someone help me out with this? I need to have the above code corrected as is with the IF ELSE's or else re-written using a CASE statement if possible. I'd appreciate it!