• You might be able to accomplish what you need in a CLR UDF. Will be a whole different animal, but might give you what you need.

    Of course, the whole problem is caused by serious violations of normal form. Is it possible, at some point in the future, to revamp the database into a more standard format?

    Another possibility, keeping it in the realm of T-SQL, would be to create an Unpivot command for each table that has Fee columns in it, and select a sum of the columns needed, depending on the table parameter. That assumes that the tables and their structures are static.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon