473,671 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7081
On Mar 23, 4:59 am, yin_n_yan...@ya hoo.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**********@ya hoo.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**********@ya hoo.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
5450
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
2324
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 & _ " WHERE (((IDU) Like 'czz*' Or (IDU) Like 'cam*' Or (IDU) _ Like 'szz*' Or (IDU) Like 'J*' Or (IDU) Like 'G*' Or (IDU) _ Like 'U*'))" & " ORDER BY IDU;"
2
1933
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, when I call the same code from the stored procedure, I get no value. The code that is executed is the same and the input parameter is the same. Does anybody have an idea? The code:
2
2621
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 other data. At the end the stored procedure cursor returns several data sets. my problem is that the report services appears to be reading only the data returned from the first loop of the cursor inside the stored procedure. It does not return the...
7
8552
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) { SqlCommand command = new SqlCommand(strProc, connection); command.CommandType = CommandType.StoredProcedure;
1
7510
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 ( ) DYNAMIC RESULT SETS 1 ------------------------------------------------------------------------
1
4302
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 stored procedure reads a value from a table, increments the value by 1 and writes it back into the table. The table is called LOADER.CAD_AT_LAST_UNIQUE_ID, and the field is LASTKEY. When I try to build the procedure I get the following message: ...
6
5088
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 procedure returns duplicates; e.g., one schedule may have multiple resources, supplies, and/or orders (and one order may have multiple foods). Is there a way to stop the duplication? The stored procedure looks like this: ...
2
2624
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 the forms. Now How do I call this stored procedure from an ASP Page using a Connection object in Server Tags <% %>. Also this stored
0
8388
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8907
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8663
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7423
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5687
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2804
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1799
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.