>Good question, my first response would be the value only. However it might be nice to be able to provide the origin of the transaction as well.
OK, about to eat dinner, but hopefully this will help....since I'm doing it for 2 tables, you can hopefully see how you'd do it for three. (with a UNION)
In the adventureworks demo DB, there are 2 tables...PurchaseOrderHeader and SalesorderHeader. They both have an order date. Suppose I wanted the max order date across both tables...
You could use this code in a scalar function...Many different ways this can be done, this is one of them.
create function dbo.GetMaxOrderDate()
returns date
as
begin
declare @FinalMaxDate date
set @FinalMaxDate = (select max(MaxDate) from
(
select max(OrderDate) as MaxDate from Purchasing.PurchaseOrderHeader
union all
select max(OrderDate) as MaxDate from Sales.SalesOrderHeader
) TempList )
return @FinalMaxdate
end
go
select dbo.GetMaxOrderDate()