I'm looking over something stupid here. Can someone tell me how to do an if statement that will do the following. I think this is close, but it's not working. Both sql statements work independently. Something crazy that I'm doing with the IF and definition of cursors I think:
CREATE PROCEDURE SW.ADD_VER_S
(IN pQUAD CHARACTER(2),
IN pSTREET CHARACTER(20),
IN pSTREET_TYPE CHARACTER(4),
IN pADDRESS_NUMBER DECIMAL(5,0))
SPECIFIC SW.ADD_VER_S
RESULT SETS 1
LANGUAGE SQL
IF pSTREET_TYPE = '' THEN
DECLARE cursor1 CURSOR WITH RETURN FOR
Select * from SW.ADDR_VERIFICATION
where QUADRANT = pQUAD
and STREET = pSTREET
and STREET_TYPE between '' and 'ZZZ'
and pADDRESS_NUMBER between LOW_ADDRESS and HIGH_ADDRESS
fetch first 1 row only ;
OPEN cursor1;
else
DECLARE cursor2 CURSOR WITH RETURN FOR
Select * from SW.ADDR_VERIFICATION
where QUADRANT = pQUAD
and STREET = pSTREET
and STREET_TYPE = pSTREET_TYPE
and pADDRESS_NUMBER between LOW_ADDRESS and HIGH_ADDRESS ;
OPEN cursor2;
end if
CREATE PROCEDURE SW.ADD_VER_S
(IN pQUAD CHARACTER(2),
IN pSTREET CHARACTER(20),
IN pSTREET_TYPE CHARACTER(4),
IN pADDRESS_NUMBER DECIMAL(5,0))
SPECIFIC SW.ADD_VER_S
RESULT SETS 1
LANGUAGE SQL
IF pSTREET_TYPE = '' THEN
DECLARE cursor1 CURSOR WITH RETURN FOR
Select * from SW.ADDR_VERIFICATION
where QUADRANT = pQUAD
and STREET = pSTREET
and STREET_TYPE between '' and 'ZZZ'
and pADDRESS_NUMBER between LOW_ADDRESS and HIGH_ADDRESS
fetch first 1 row only ;
OPEN cursor1;
else
DECLARE cursor2 CURSOR WITH RETURN FOR
Select * from SW.ADDR_VERIFICATION
where QUADRANT = pQUAD
and STREET = pSTREET
and STREET_TYPE = pSTREET_TYPE
and pADDRESS_NUMBER between LOW_ADDRESS and HIGH_ADDRESS ;
OPEN cursor2;
end if