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
 QUERY REQ

Author  Topic 

Anushka
Yak Posting Veteran

79 Posts

Posted - 2008-04-22 : 08:50:38
I RECEIVED THIS QUERY...
I NEED IF FOR EXAMPLE QTY IS SELECTED FROM DIFF TABLE THEN HOW TO WRITE THE QUERY...
SELECT t.ID,
t.ITEMID,
t.DATE,
t.QTY
FROM
(SELECT ROW_NUMBER() OVER( PARTITION BY ITEMID Order BY DATE DESC) AS RowNo,
ID,
ITEMID,
DATE,
QTY
FROM YourTable
)t
WHERE t.RowNo=1
ORDER BY T.ID

ITS URGENT...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-22 : 08:55:20
[code]SELECT t.ID,
t.ITEMID,
t.DATE,
t.QTY
FROM
(SELECT ROW_NUMBER() OVER( PARTITION BY t1.ITEMID Order BY t1.DATE DESC) AS RowNo,
t1.ID,
t1.ITEMID,
t1.DATE,
t2.QTY
FROM YourTable1 t1
INNER JOIN YourTable t2
ON t1.commonfield=t2.commonfield
)t
WHERE t.RowNo=1
ORDER BY t.ID[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-22 : 08:55:35
The query above that was given to you from here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101473
is for fetching non-dupliate records.

You REALLY should read this blog post http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
if you want URGENT help.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -