Stored Procedure with override?

  • I received a request to create a stored proc with following:

    I have a view with the following columns

    (table1 - AppCode, AgencyID, CompnyID, CustCode, CustVal)

    I have a proc that will take the following parameters and return all matching rows (AppCode, AgencyID, CompnyID, CustCode(optional))

    The trick: Any customcode with the CompnyID should override the AgencyID parameter.

    Can anyone point me in the right direction with this? Any help would be greatly appreciated. Thx!

  • I think you need something like this:

    Create procedure ProcedureName @AppCode int, @AgencyID int, @CompnyID int, @CustCode int=null

    as

    select @AgencyID = coalesce(@CustCode,@AgencyID)

    select AppCode, AgencyID, CompnyID, CustCode, CustVal

    from table1

    where appcode = @appcode and agencyid = @agencyID and CompnyID = @CompnyID

  • Thank you very much Adam!

  • Glad it helped you out.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply