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
 thanx visakh16 n raky but.............

Author  Topic 

Anushka
Yak Posting Veteran

79 Posts

Posted - 2008-04-22 : 07:49:31
ID ITEMID DATE QTY

1 XYZ 1/1/2008 1
2 XYZ 2/4/2008 3
3 XYZ 34/2008 2
4 ABC 1/3/2008 4
5 ABC 1/4/2008 1
6 CAB 12/4/2008 3

Actually i neeed max(date) record....

as the id is unique
if i will do group by itemid it is not possible...as id is unique (again iam getting all values)

[i wrote select max(date),itemid,date,qty from table group by id,itemid,qty-this is 100% wrong].....

O/P:This is the o/p i require

ID ITEMID DATE QTY
3 XYZ 34/2008 2
5 ABC 1/4/2008 1
6 CAB 12/4/2008 3

so,how it is possible.........[is it trough courser's it possible,if so how]


Hi,
Thanx for reply for my previous post....iam getting o/p if i retrive from single table ...
but the fields are from different tables i have to select
for example i wrote:

select p.receiveddate AS [Last Received Date],
P.PURCHASENUMBER AS [Ref Doc#],
p.itemid AS [Item ID],
P.DESCRIPTION AS [Description],
I.QtyOnHand [Stock As On Date],
P.ITEMUNITPRICE as [Rate],
P.SUBTOTAL as [Value],
P.ReceivedQty as [Received Qty]

FROM
(SELECT ROW_NUMBER() OVER( PARTITION BY p.ITEMID Order BY p.receiveddate DESC) AS RowNo,
receiveddate,
PURCHASENUMBER,
ITEMID,
DESCRIPTION,
QtyOnHand,
ITEMUNITPRICE,
SUBTOTAL,
ReceivedQty
FROM pURCHASEDETAIL P,inventorybywarehouse i
)t
WHERE t.RowNo=1
ORDER BY p.PURCHASENUMBER

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-22 : 07:50:51
Duplicate post
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101473



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

- Advertisement -