Home Forums SQL Server 2008 SQL Server Newbies Function Calls two other functions - If, else - then used in View - Is it OK or can it be improved RE: Function Calls two other functions - If, else - then used in View - Is it OK or can it be improved

  • Mile Higher Than Sea Level (7/7/2014)


    Id_Wells on Wells table is an PK (unique)

    I totally forgot to include R_35 - thanks for the reminder.

    As per my Missive above...

    This Discrete Rule calls 2 sub-Discrete Rules.

    While that might seem somewhat redundant, there are other Discrete Rules that call many multiple sub-Discrete Rules.

    For example, some will have Case statement. Example: If in ND and Native Land

    ALTER FUNCTION [dbo].[R_35](@ID_Wells int)

    RETURNS int

    AS

    BEGIN;

    DECLARE @Result as int;

    set @Result = (SELECT dbo.R_35A(ID_Wells) AS R_35A

    FROM dbo.Wells where ID_Wells = @ID_Wells);

    if @Result =1

    set @Result = -1-- -1 is True in Access

    else

    begin

    set @Result = (SELECT dbo.R_35B(ID_Wells) AS R_35B

    FROM dbo.Wells where ID_Wells = @ID_Wells);

    if @Result =1

    set @Result = -1-- -1 is True in MS Access (The client application)

    else

    set @Result =0 -- 0 is False in Access

    end

    return @result

    END;

    The function above was in your initial post. What I was asking about is the target of the FROM clause in the following function:

    CREATE FUNCTION [dbo].[R_35B](@ID_Wells int)

    -- Rule 35 has part A that can be true, if not then part B must be true

    -- the two of these make up Rule 35

    RETURNS int

    AS

    BEGIN;

    DECLARE @Result int;

    SELECT @Result = SIGN( COUNT(*) )

    FROM R_35_Result -- <<<<< This, it is either a table or view but we don't know what

    WHERE (ID_Wells = @id_Wells);

    Return @Result

    END;

    GO