SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 how to get the data only once
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Suradhi
Starting Member

India
2 Posts

Posted - 07/29/2013 :  02:33:00  Show Profile  Reply with Quote
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)

Singapore
17635 Posts

Posted - 07/29/2013 :  03:18:06  Show Profile  Reply with Quote
show us your query


KH
Time is always against us

Go to Top of Page

Suradhi
Starting Member

India
2 Posts

Posted - 07/29/2013 :  03:56:14  Show Profile  Reply with Quote
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

India
22755 Posts

Posted - 07/29/2013 :  04:00:49  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000