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 2008 Forums
 Analysis Server and Reporting Services (2008)
 Left join cause duplicate rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

under2811
Constraint Violating Yak Guru

India
356 Posts

Posted - 04/18/2013 :  17:47:15  Show Profile  Reply with Quote
Hi
I am preparing report where i have merged multiple subreport queries into single query with joins. I am getting records but for certain sets I am getting duplicates. How to avoid it in report display? I have tired to set Hide duplicate for perticular table, it hides and only show one record but it shows also blank row for duplicate records.

I am try to show my report hoe looks like below where middle Emp Details table is getting duplicate values. Help me out. Thanks

Report::
Manger AAA Dept 10
Date xx-xx-xxxx Return XYZ

Emp Details
ID NAME CITY State
1 A XXX YYY
1 A XXX YYYPage1
1 A XXX YYY

Profile
ID Create Modified UserNm
1 xx-xx-xxxx yy-yy-yyyy ABC
2 dd-mm-yyyy dd-mm-yyyy EFG

Manger BBB Dept 20
Date xx-xx-xxxx Return RTY

Emp Details
ID NAME CITY State
1 A XXX YYY
2 B ZZZ FFFPage2
3 C GGG TTT

Profile
ID Create Modified UserNm
3 xx-xx-xxxx yy-yy-yyyy YUI
4 dd-mm-yyyy dd-mm-yyyy JKG

Edited by - under2811 on 04/18/2013 17:50:37

James K
Flowing Fount of Yak Knowledge

3587 Posts

Posted - 04/18/2013 :  18:33:49  Show Profile  Reply with Quote
Post the query you are using. Usually you can use an aggregate function or row_Number function to remove the duplicate. Here is a simplified example - you could do something like that.
create table #Emp(id int, name varchar(32));
create table #EmpPhones(empid int, phonenumber varchar(32));
insert into #Emp values (1,'JK'),(2,'U2');
insert into #EmpPhones values (1,'2125551212'),(1,'2035551212'),(2,'9145551212');

-- gives multiple rows
select id,name,phonenumber
from #Emp e inner join #EmpPhones ep on ep.EmpId = e.id;

-- picks one phone number and shows only one row per employee
select id,name,phonenumber from
(
	select id,name,phonenumber,
		row_Number() over(partition by id order by phonenumber) as RN
	from #Emp e inner join #EmpPhones ep on ep.EmpId = e.id
) s where RN = 1;

drop table #Emp, #EmpPhones;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/19/2013 :  02:54:32  Show Profile  Reply with Quote
so whats should be your expected output for your posted data above? what according to you represents a duplicate?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

under2811
Constraint Violating Yak Guru

India
356 Posts

Posted - 04/19/2013 :  10:53:22  Show Profile  Reply with Quote
Got it.. I used property "Hide duplicate" in report.
Thanks for your all reply.
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.08 seconds. Powered By: Snitz Forums 2000