Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning Last Tranaction Date
Message
From
03/12/2013 17:16:46
 
 
To
03/12/2013 17:11:19
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Desktop
Miscellaneous
Thread ID:
01589211
Message ID:
01589222
Views:
50
>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


-- test it out....
select dbo.GetMaxOrderDate() 
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform