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 2000 Forums
 Transact-SQL (2000)
 Inner joins/outer joins

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-07-18 : 09:19:23
I have a one to many relationship - tblSL_Calls (one) tblSL_CallDiary (many). I am running a crystal report and if there is more than one entry in tblSL_Call Diary I get the records repeated that number of times. I believe it is due to my join being wrong. Can any help me please. Here's the sql of the crystal report.
TIA
SELECT "tblSL_Calls"."CallNo", "tblSL_Calls"."Call_date", "tblSL_Calls"."Call_desc", "tblSL_Calls"."Surname", "tblSL_Calls"."Title", "tblSL_Calls"."Add1", "tblSL_Calls"."Add2", "tblSL_Calls"."Add3", "tblSL_Calls"."Add4", "tblSL_Calls"."PostCode", "tblSL_Calls"."Area", "tblSL_Calls"."Division", "tblSL_Calls"."Service", "tblSL_Calls"."Completed_time", "tblSL_Calls"."Cancelled", "tblSL_Calls"."Tel_no", "tblSL_CallDiary"."Entrydate", "tblSL_CallDiary"."Diary_Description"
FROM "PCCContactCentre"."dbo"."tblSL_Calls" "tblSL_Calls" LEFT OUTER JOIN "PCCContactCentre"."dbo"."tblSL_CallDiary" "tblSL_CallDiary" ON "tblSL_Calls"."CallNo"="tblSL_CallDiary"."CallNo"
WHERE "tblSL_Calls"."Service"='BULKY HOUSEHOLD COLLECTIONS' AND "tblSL_Calls"."Completed_time" IS NULL AND "tblSL_Calls"."Cancelled" IS NULL AND "tblSL_Calls"."Division"='Environmental Services' AND "tblSL_Calls"."Area"='North'
ORDER BY "tblSL_Calls"."PostCode", "tblSL_Calls"."Area"

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-07-18 : 09:31:13
with a one to many relationship, if you are showing values from the many table than values from the one table will be repeated for each many value (unless you are grouping by the one value and aggregating the many values)

if I'm not getting you problem, then post the DDL of the 2 tables, some sample data (in the form of insert statements) and the expected results.



set nocount on
declare @one table (oneid int, oneval varchar(10))
declare @many table (oneid int, manyval char(1))

insert @one
select 1, 'one' union
select 2, 'two' union
select 3, 'three'

insert @many
select 1, 'a' union
select 1, 'b' union
select 1, 'c' union
select 2, 'a' union
select 2, 'b'

select * from @one
select * from @many

--straight select with outer join
select a.oneval
,b.manyval
from @one a
left outer join @many b on a.oneid = b.oneid

--aggrate with group by
select a.oneval
,max(b.manyval) maxManyVal
from @one a
left outer join @many b on a.oneid = b.oneid
group by a.oneval


Be One with the Optimizer
TG
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-07-18 : 09:37:30
I think I need a subreport in my crystal report to display the diary entries. That's what I'm looking at now anyway. Thanks for your help. I may get back to you later.
Go to Top of Page
   

- Advertisement -