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 2008 Forums
 Analysis Server and Reporting Services (2008)
 Left join cause duplicate rows

Author  Topic 

under2811
Constraint Violating Yak Guru

366 Posts

Posted - 2013-04-18 : 17:47:15
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

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-18 : 18:33:49
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

52326 Posts

Posted - 2013-04-19 : 02:54:32
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

366 Posts

Posted - 2013-04-19 : 10:53:22
Got it.. I used property "Hide duplicate" in report.
Thanks for your all reply.
Go to Top of Page
   

- Advertisement -