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 2005 Forums
 Transact-SQL (2005)
 query

Author  Topic 

krish001
Yak Posting Veteran

61 Posts

Posted - 2010-03-22 : 01:09:04
I need a query where iam using


select max(column1),column2 from table where column1 <=getdate()

by this iam getting a group by error to add column2 but i dont want how to avoid group by

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-03-22 : 01:24:49
Try this!

select max_date,b.column2 from
(select max(column1) as max_date from table where column1 <=getdate()) a
inner join table b on b.column1=a.max_date

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-22 : 11:43:09
may be this?

select distinct max(case when column1 <=getdate() then column1 else null end) over (partition by column2),column2 from table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -