472,967 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,967 software developers and data experts.

SQL stored procedure returns duplicates

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.

Mar 22 '07 #1
4 7039
On Mar 23, 4:59 am, yin_n_yan...@yahoo.com 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.

Mar 23 '07 #2
On 22 Mar 2007 15:59:59 -0700, yi**********@yahoo.com wrote:
>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?
Hi yin_n_yang74,

You are trying to pair basically unrelated things (yes, both equipment
and food are related to an event, but there is no relationship between a
particular food row for an event and a particular equipment row for the
same event). That's why the join causes the information to be
duplicated. More aboout this problem, and a possible solution if you
want to solve this server-side, is on my blog:
http://sqlblog.com/blogs/hugo_kornel...ated-rows.aspx

However, the best solution is to handle this client side. I must admit
that I know nothing about Crystal Reports. But IF CR can handle it, I'd
advise you to open two seperate rowsets at once (one for event and food
information, using a basic joined query and ordering by event, and one
for the equipment information, also odered by event). Then process row
from both recordsets in a balanced line fashion: read one row from each
set and generate an output line until one set changes event; at that
point deplete the other set until it too changes event. Repeat until
both sets are exhausted.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Mar 23 '07 #3
yi**********@yahoo.com 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?
Never mind the stored procedure, have Crystal read the tables
directly: Event from the main report, Food from a subreport,
Equipment from a second subreport. Pass the primary key of
Event to each subreport as a parameter, linking it to the
appropriate foreign key within the subreport.
Mar 24 '07 #4
Thank you all for your helpful hands. However, I realized that I was
not putting enough information, which makes it difficult for you to
help me. I will make a new post with more complete information. You
have helped me get closer to what I need, though - thanks!

Apr 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
by: franjorge | last post by:
Hi, I have created two stored procedures via VB using this code: sql = "CREATE PROC " & nombre_proc & " AS SELECT *" & _ " From MBM_PUNTOS_SCE_SIN_COINCIDIR_SIEGE_FALTA_PM_NE_" & mes & _ "...
2
by: nikolacace | last post by:
Hi, I have a stored procedure (the code is below) that I use to retrieve one value from my database. I tested the code in Query Analyzer, and it works (I get the value I was looking for). However,...
2
by: andres | last post by:
hi all, thanks for everyone for your support! i have a report being built in studio 2005. It calls a stored procedure. The SP runs a query and gets a data set which then loops through to get...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
1
by: peaceburn | last post by:
Hi, I'm gonna pull my hair in the coming days with these DB2 stored procedures. So the issue, let's assume a simple stored procedure like this : CREATE PROCEDURE MYSCHEMA.PROCEDURE1 ( )...
1
by: gregoryday | last post by:
I am battling to get a stored procedure to build: I have a stored procedure working in SQL Server 2000, and now need to port it to DB2. I will be accessing the stored procedure via VB.NET. The...
6
by: yin_n_yang74 | last post by:
I am trying to create a report in Crystal Reports (v 8.5). I have a stored procedure to pull data from two databases and parameters. There are multiple one-to-many relationships and the stored...
2
by: =?Utf-8?B?YW5vb3A=?= | last post by:
Hello, I have a stored procedure named as usp_CheckLogin with two parameters as @usID, @Password also values of these parameters are to be extracted using Request.Form from the fields in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.