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 2012 Forums
 Transact-SQL (2012)
 how to get the data only once

Author  Topic 

Suradhi
Starting Member

2 Posts

Posted - 2013-07-29 : 02:33:00
The report contains order_id,ordername,volume,weight due to the volumw and weight differing the orderid is displayed more than once could some one help me on how to get the data for only once????.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-07-29 : 03:18:06
show us your query


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

Go to Top of Page

Suradhi
Starting Member

2 Posts

Posted - 2013-07-29 : 03:56:14
Here is the query!!!


SELECT
co.reference_id as Order_Number,
co.order_id as Pick_ID,

count(distinct ct.art) as Articles,
sum(ct.ordered_qty * a.nopa) as Packages,
sum(a.weig)/1000 as Weight,
sum(a.avol)/100000 as Volume,
sum(ct.ordered_qty) as Ordered_qty,
sum(ct.picked_qty) as Picked_qty,
sum(ct.checked_qty) as Checked_qty


FROM
alpha co,
beta ct,
tablea a

WHERE
co.order_id = ct.order_id
and ct.art = a.art


GROUP BY
co.order_reference_id,
co.order_id,
ct.ordered_qty,
ct.picked_qty,
ct.checked_qty
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-07-29 : 04:00:49
You need to include only non-aggregate columns in the GROUP BY statement

SELECT
co.reference_id as Order_Number,
co.order_id as Pick_ID,

count(distinct ct.art) as Articles,
sum(ct.ordered_qty * a.nopa) as Packages,
sum(a.weig)/1000 as Weight,
sum(a.avol)/100000 as Volume,
sum(ct.ordered_qty) as Ordered_qty,
sum(ct.picked_qty) as Picked_qty,
sum(ct.checked_qty) as Checked_qty


FROM
alpha co,
beta ct,
tablea a

WHERE
co.order_id = ct.order_id
and ct.art = a.art


GROUP BY
co.order_reference_id,
co.order_id


Madhivanan

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

- Advertisement -