Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with this query

Author  Topic 

joblot1976
Starting Member

10 Posts

Posted - 2005-07-11 : 22:01:43
How can i find max date and close value corresponding to that date. The following query doesn't work as A.Close is not a part of aggregate function and using group by on A.Close gives undesired results.

SELECT MAX(A.Date), A.Close
FROM (tblSecurityDay A INNER JOIN tblSecurity B ON A.SecurityID = B.SecurityID)
INNER JOIN CompanyDetails C ON B.SecurityCode = C.CompanyCode AND B.CompanyKey = C.CompanyKey
WHERE C.CompanyCode = 'ABC' AND C.CompanyKey = 1

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-07-12 : 00:42:16
If you use aggregate function you need to group it by a Column
quote:
using group by on A.Close gives undesired results.

Then post table structures, sample data and the Desired Result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-07-12 : 02:30:32
Sounds familiar
Have a look at this previous post

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=51964

If this doesnt help then, as madhivanan said, post DML & DDL etc

Andy

Beauty is in the eyes of the beerholder
Go to Top of Page
   

- Advertisement -