[dba-SQLServer] Calling function from a query

Darren DICK darrend at crhorizons.com.au
Mon Oct 24 01:03:48 CDT 2005


Hello all

What I have is a function that will (in this case) determine those records
from the Account table that are now 'cancelled'

In this example the cancelled status is true if there is a cancelled date in
the Account Table  and the Account status code is M
Those 2 things combined need to occur to determine a cancelled record

So rather than copy and paste the contents of the function below into each
and every occurrence of testing for 'cancelled'
I want a function to determine those 2 criteria then select all records from
the Account table that meet the criteria as determined in the function

IE how do I call the function from the query and do it 'on the fly'

Make sense?

Lemme know

Many thanks in advance

Darren

___________________________________________________
SQL = select * from Account  where  Account_IsCancelled(a)
    
FUNCTION = fn Account_IsCancelled(a as Account)
begin
    return (a.AccountStatusCode <> 'M' and
            a.DateCancelled is not null) end

Darren




More information about the dba-SQLServer mailing list