I want to implement this type of logic, using DB2:
Create Procedure sp_MyProcedure (
IN Var1 Decimal(6, 0),
IN Var2 Decimal(6, 0)
) Language SQL
Dynamic Result Sets 1
Begin
If Exists(Select * from MyTable where CustomerNbr = Var1) Then
return (Select * from MyTable where CustomerNbr = Var1)
Else If Exists(Select * from MyTable where CustomerNbr = Var2) Then
return (Select * from MyTable where CustomerNbr = Var2)
Else
return (Select * from MyTable where CustomerNbr = 0)
End If
End
But can't figure out the syntax to implement this type of logic. Plus, I am running each query twice; once to check that it returns values and, if it does return values, once to create the returned set of data. So, I know there has to be a better way. I have been looking at the "With" statement to create temporary tables but, so far it has essentially the same issues of inefficiency and syntax limits.
(I apologize for the formatting of the code. I can't seem to get it to work right in this text editor) Can someone suggest the best way to accomplish this? Thanks, in advance, for your advice.