SQLTeam.com | Weblogs | Forums

Need a QUERY in SQL SERVER 2014

mysql
sql2014
sql2012

#1

Hello,
I’m using SQL Server 2014 and i’m having a problem with a Query:

I want to have in my report, ALL the items of the ordre « ID_Order = 9 » that have been delivered. And for the items that have been Delivered in two times (Item Code = Art3 for exemple) I just want to have the last row, that meens the last delivery of this Item, with NO repetition.

I already tried this two queries without success :
1* DISTINCT

SELECT DISTINCT Order.ItemCode, Delivery. Qty, Delivery.ID_Delivery, Order.ID_Order
FROM Delivery
inner join Order ON Order.ID_Order = Delivery.ID_Order
where Order.ID_Order = '9'

2* SUBQUERY

select * from (Select Order. ItemCode, Delivery. Qty, from Delivery
inner join Order ON Order.ID_Order = Delivery.ID_Order
where Order.ID_Order = '9')
group by a.ItemCode, a.Qty

Thank you in advance !


#2

Please follow forum netiquette posting create table DDL or declare table variable and include insert statement(s),
Thanks