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.
| 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 ondeclare @one table (oneid int, oneval varchar(10))declare @many table (oneid int, manyval char(1))insert @oneselect 1, 'one' unionselect 2, 'two' unionselect 3, 'three'insert @manyselect 1, 'a' unionselect 1, 'b' unionselect 1, 'c' unionselect 2, 'a' unionselect 2, 'b'select * from @oneselect * from @many--straight select with outer joinselect a.oneval ,b.manyvalfrom @one aleft outer join @many b on a.oneid = b.oneid--aggrate with group byselect a.oneval ,max(b.manyval) maxManyValfrom @one aleft outer join @many b on a.oneid = b.oneidgroup by a.oneval Be One with the OptimizerTG |
 |
|
|
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. |
 |
|
|
|
|
|
|
|