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
 General SQL Server Forums
 New to SQL Server Programming
 querey not working

Author  Topic 

kiruthika
Yak Posting Veteran

67 Posts

Posted - 2007-12-01 : 01:40:40
Hi!

This is my table
----------------
create table brand(lno int,date1 datetime,pdes varchar(15))
insert brand values(1,getdate(),'First Pdt')
insert brand values(1,getdate(),'SEc pdt')
insert brand values(2,'2007-11-01 2:13:01.123','Thir desc')
insert brand values(2,'2007-11-01 3:13:01.123','4th desc')


I want this output:
--------------------

pdes date1
-------- ---------
SEc pdt 2007-12-01 10:14:13.263

4th desc 2007-11-01 03:13:01.123

I tried this querey but it is not working! please anyone help me!

select t.pdes,t.date1 from brand t join (select convert(varchar(12),max(date1))as date1 from brand group by lno) t1
on t1.date1=t.date1

Thank You!


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-01 : 01:48:43
why are you converting the date to string ?

select t.pdes,t.date1 from brand t join (select max(date1)as date1 from brand group by lno) t1
on t1.date1=t.date1



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kiruthika
Yak Posting Veteran

67 Posts

Posted - 2007-12-01 : 02:17:43
Hi!

Thank you for your help. Thank you so much.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-01 : 04:57:47
or

select * from brand as t where date1=
(select max(date1) from brand where lno=t.lno)


Madhivanan

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

- Advertisement -