Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning Last Tranaction Date
Message
De
03/12/2013 17:16:46
 
 
À
03/12/2013 17:11:19
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01589211
Message ID:
01589222
Vues:
49
>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() 
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform