lundi 11 janvier 2021

Run different SQL statements using If Then with a variable

Trying to do something very simple. Using If/Then, is there a way to run a separate Select statement based on the value of a variable? The function GetTotalActiveUnits() in the below code returns an integer.

    set @RetVal =  GetTotalActiveUnits(CustomerCode);
    if  @RetVal = 0 then 
    Select * from tblREF_UnitInfo;
    else
    select * from tblREF_State;
    end if

Aucun commentaire:

Enregistrer un commentaire