Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SQL Server 2000 Group By asking for aggregate function when it is supplied
  2. SELECT     c.ContractID, max( cs.ContractStatusCreated)
  3. FROM       dbo.NMPT_Contract AS c INNER JOIN
  4.            dbo.NMPT_ContractStatus AS cs ON c.ContractID = cs.ContractID INNER JOIN
  5.            dbo.CMSS_Status AS s ON cs.StatusID = s.StatusID
  6. group by  c.ContractID
  7. having cs.ContractStatusCreated = MAX(cs.ContractStatusCreated)
  8.        
  9. select     ContractID, ContractStatusCreated
  10. FROM       dbo.NMPT_Contract AS x INNER JOIN            
  11.            dbo.NMPT_ContractStatus AS y ON x.ContractID = y.ContractID
  12. where (x.ContractID, y.ContractStatusCreated) = (
  13.     SELECT     c.ContractID, max( cs.ContractStatusCreated)
  14.     FROM       dbo.NMPT_Contract AS c INNER JOIN            
  15.                dbo.NMPT_ContractStatus AS cs ON c.ContractID = cs.ContractID INNER JOIN            
  16.                dbo.CMSS_Status AS s ON cs.StatusID = s.StatusID
  17.     group by  c.ContractID
  18. )