Home Forums SQL Server 7,2000 T-SQL Any experts in SQL 2000 (Multi-statement table-valued function) query. RE: Any experts in SQL 2000 (Multi-statement table-valued function) query.

  • You can join to a UDF that returns a table.   You might need to adjust your UDF to suit - I assume that the parameter for this is currently the customerid.  Have a look at the following - it might be something like what you are after

    create table myCustomerTable (custid int, custname varchar (100))

    go

    Insert into myCustomerTable values (1, 'Cust 1')

    Insert into myCustomerTable values (2, 'Cust 2')

    go

    create function fnMYTABLEUDF ()--(@vintCustid Int)

    Returns @Lookup Table (CustID Int, CustDate smalldatetime)

    As

    Begin

    -- this pretends to be whatever logic is in your UDF

     Insert Into @Lookup Values (1, '1 Jan 2004')

     Insert Into @Lookup Values (2, '25 Jun 2004')

    return

    ENd

    go

    select * from myCustomerTable

    Select * from myCustomerTable

     Inner Join fnMYTABLEUDF () x

      On myCustomerTable.custid = x.custid

     Where x.custdate > '1 jan 2003'

    Select * from myCustomerTable

     Inner Join fnMYTABLEUDF () x

      On myCustomerTable.custid = x.custid

     Where x.custdate > '1 jan 2004'