Home Forums SQL Server 2008 SQL Server Newbies Create UDF (Function) with one parameter - returns True/False from VBA code RE: Create UDF (Function) with one parameter - returns True/False from VBA code

  • Mile Higher Than Sea Level (6/19/2014)


    Thanks! I didn't think about that. (where is my V8 icon).

    I was busy cobbling this together when you responded.

    The Rule Engine components are designed to return each of the 100 Base Rules as a True - False based on Query criteria.

    Let me try that out and come back to mark it as an anwser.

    CREATE FUNCTION dbo.Rule71(@ID_Wells int) RETURNS int

    AS

    BEGIN;

    DECLARE @Result int;

    SET @Result = SELECT COUNT(*) AS "SELECT Wells.ID_Wells, Wells.Well_Name, Wells.ClassificationID FROM Wells WHERE (((Wells.ID_Wells)=" & @ID_Wells & ") AND ((Wells.ClassificationID)=3));

    IF @Result = 0

    Return 0; -- False

    else

    Return 1; -- True

    end;

    END;

    go

    SELECT R_71, dbo.Rule71(ID_Wells) AS Rule71

    FROM dbo.StatusTable;

    Instead of a scalar function I would use the itvf version. A slight change to your query will yield some decent performance gains.

    SELECT R_71, Rule71.MyResult

    FROM dbo.StatusTable

    cross apply dbo.Rule71(ID_Wells) as Rule71

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/