• And this rewrite of the function should work like the one Chris provided in-line in his code.

    CREATE function [dbo].[woccsr_ts_amt] (

    @wo_id varchar(24),

    @cc_id varchar(24),

    @gl_id varchar(24))

    returns TABLE

    as

    RETURN

    select

    sum(idr.detail_amount + idr.crdb_adj_amount) as approved_ts_amount

    from

    dbo.pay_detail as idr

    inner join dbo.ts nr

    on nr.ts_id = idr.incurred_id

    where

    nr.wo_id = @wo_id

    and idr.cc_id = @cc_id

    and idr.gl_id = @gl_id

    and nr.status in (1, 3, 44, 52);