Re: SQL stored procedure returns duplicates



On Mar 23, 4:59 am, yin_n_yan...@xxxxxxxxx wrote:
I am new to SQL and SQL Server world. There must be a simple solution
to this, but I'm not seeing it. I am trying to create a crystal
report (v8.5) using a stored procedure from SQL Server (v2000) in
order to report from two databases and to enable parameters.

When I create the stored procedure, it joins multiple one-to-many
relationship tables. This results in repeated/duplicate records. Is
this an issue that should be solved within the stored procedure, or is
this inevitable? If latter, how do you eliminate the duplicates in
Crystal Reports?

Let's say we have three different tables - Event, Food, Equipment.
Each event may have multiple food and multiple equipments; some events
may not have food and/or equipments. The stored procedure outcome may
look like this:

Event Food Food_Qty Equipment
Equipment_Qty

Event1 Food2 10 Equipment5
1
Event1 Food4 10
NULL NULL
Event2 Food4 50 Equipment2
10
Event2 Food4 50 Equipment5
2
Event2 Food1 12 Equipment2
10
Event2 Food1 12 Equipment5
2

As you can see in Event2, for each Food variations, Equipment values
repeat. When I am creating a Crystal Reports, I have the duplication
problem.

What I would like to see in the report is either:

Event1
Food2, 10 Equipment5, 1
Food4, 10
Event2
Food4, 50 Equipment2, 10
Food1, 12 Equipment5, 2

OR:

Event1
Food2, 10
Food4, 10
Equipment5, 1
Event2
Food4, 50
Food1, 12
Equipment2, 10
Equipment5, 2

Attempt1: Using "Eliminate Duplicate Record" option does not work with
the Equipment section since CR does not recognize "Equipment2" in the
third line of the table and "Equipment2" in the fifth line of the
table as duplicates.

Event1 Food2, 10 Equipment5, 1
Food4, 10
Event2 Food4, 50 Equipment2, 10
Equipment5, 2
Food1, 12 Equipment2, 10
(duplication)
Equipment5, 2
(duplication)

Attempt2: I created group for each category (Event, Food, Equipment),
put the data in Group Headers and used "Suppress Section" to eliminate
if the same equipments are listed more than once within the Food
group. This eliminated the duplication, but the items do not align
correctly.

Event1 Food2, 10 Equipment5, 1
Food4, 10
Event2 Food4, 50 Equipment2, 10
Equipment5, 2
Food1, 12 (I want this to appear right below the
'Food4, 50' line)

I would really appreciate any suggestions! Thank you in advance.

Hi,
When you joined with multiple tables it will produce duplicates. One
way is to create a temp table and store the values from one table.
Let's say the Event table. Now your rows are fixed and there are no
duplicates. Then you update the remaining columns lets say you join
with the Food and Equipment table.

.



Relevant Pages

  • SQL stored procedure returns duplicates
    ... order to report from two databases and to enable parameters. ... Let's say we have three different tables - Event, Food, Equipment. ... When I am creating a Crystal Reports, I have the duplication ...
    (comp.databases.ms-sqlserver)
  • Re: BT Wayleaves
    ... I saw a report in the paper recently where a company had used a false address ... but the electricity companies attitude to why they ... There is always the possibility this is stolen equipment but seems to me to be a mistaken purchase as unsuitable for the jobs they had in mind. ... If the equipment *is* stolen and police enquiries lead to your property, it may be much more difficult for you to avoid prosecution and the questioning will not be so friendly. ...
    (uk.business.agriculture)
  • RE: Query wont report
    ... I went back to begining queries and concatonated and [sanitation ... Jerry Whittle, Microsoft Access MVP ... I also have equipment table and department table linked from ... Now I want to generate a report grouped by location that identifies tasks ...
    (microsoft.public.access.gettingstarted)
  • Re: display week dates between to different dates
    ... equipment history doesn't go by actual dates - it goes by the requisition #. ... Maxis the current job that a piece of equipment is on. ... the workers complete a driver report each day for a vehicle. ... Type something like this into the Field column in query design: ...
    (microsoft.public.access.modulesdaovba)
  • Re: Creating a report from a table with most info blank
    ... You should have an Equipment table (which lists all equipment ... as a Foreign Key field and then the repair details. ... THE INFORMATION GLEANED IS FROM A PAPER FORM TITLED MALFUNCTION REPORT THAT ... THE QUERY IS OPENS WITH A REQUEST FOR A DATE RANGE AND DRAWS OUT ALL ROWS THAT DO NOT HAVE A REPAIR LISTED. ...
    (microsoft.public.access.reports)

Loading