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

  • Seems a little odd but here are two ways you could do it. The first is a **ACK**Scalar Function**ACK**, the second is much the same logic but as an inline table valued function. In both cases I am using a property of the implicit conversion to bit. If the value is >= 1 the value of a bit will always be 1. 😉

    create function Rule71

    (

    @ID_Wells int

    )

    returns bit as begin

    declare @TrueFalse bit

    select @TrueFalse = COUNT(*)

    FROM Wells

    WHERE Wells.ID_Wells = @ID_Wells

    AND Wells.ClassificationID = 3

    return @TrueFalse

    end

    go

    create function Rule71_itvf

    (

    @ID_Wells int

    )

    returns TABLE

    as

    RETURN

    select CAST(COUNT(*) as bit) as MyResult

    FROM Wells

    WHERE Wells.ID_Wells = @ID_Wells

    AND Wells.ClassificationID = 3

    end

    _______________________________________________________________

    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/