Solved

Crystal Reports 2011 Table Join

Posted on 2014-11-04
7
131 Views
Last Modified: 2014-11-11
Crystal Reports 2011.  Connecting via ODBC  to Pervasive 11 database.

I wish to link 2 tables.  The first table is the Master record holder.  The second table holds all the underlying detail.

The join is very simple - Table 1.Quote# right outer join Table 2.Quote#_Add. (not enforced).

e.g. Table 1.Quote# 45199 = Table 2.Quote#_add 45199

However the database provides a function allowing additional items to be added to the master record but identified as supplementaries.  i.e. they are form part of the master record as a whole but also can be identified as additional to the original value.  For example: initial quote $1000 additional damage found during repair to the value of $500.  This $500 would be added as a supplementary of the original quote rather than creating a whole other quote.

The way the database does this is simple.  It adds a sequential counter.  The master record will always be XXXXX.00 and any supplementaries will be sequential XXXXX.01, XXXXX.02 etc.

Supplementaries are infrequent but without the correct join there is holes within our datasets.

So the issue is how do I join the two tables to include any supplementaries?  

The current join Table 1.Quote# right outer join Table 2.Quote#_Add. (not enforced).  Includes all information but excludes all supplementaries.  This would be because the is no longer an exact match once the suffix changes incrementally but I don't know how to work around this.........

Appreciate your help.
0
Comment
Question by:Murphy1992
  • 3
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Koen Van Wielink
ID: 40423257
Can you join the master table to a second instance of this table, basically treating it the same way as you would the detail table? So it would use the master table to get the quote number, then join to itself under another alias to get the supplementary charges, and it would join to the detail table for the remaining details.
0
 

Author Comment

by:Murphy1992
ID: 40423285
Thank for response.
Know where you are heading with this but still believe the issue is the exclusion as it isn't an exact match.  i.e. Crystal provides only for an exact match.  It doesn't allow for value >= as master record and < next master record.

e.g.

Table 1.Quote#
44291.00

Table 1.Quote#_Add
44291.00
44291.00
44291.00
44291.00
44291.01
44291.02
44291.02
44291.02

It's the all the records >=44291 and <44292 that should be matched to master record 44291.

At this stage Crystal matches only records equal to 44291.00
0
 
LVL 13

Accepted Solution

by:
Koen Van Wielink earned 350 total points
ID: 40423290
Ok, I see your problem. Do you have the option to create a custom query? I would tackle this through a nested subquery or a temporary table (using a stored procedure).
You can extract the portion of the field before the period separately with something like this:

select T2.*
From (Select substring(T1.Quote#, 0, charindex('.',T1.Quote#)) as 'MasterRecord, T1.*)
            From Table1 T1) as T2

Open in new window


I hope this syntax is usable on a pervasive database, I'm not familiar with the exact syntax. But if not the idea would apply I'm sure.
Apply the same logic on your second table with the details, and you have the field on which you can join the data together.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 150 total points
ID: 40423481
I have no idea why you start with a right outer join, is there a particular reason for that choice?

also: instead of "charindex" you need "locate" then you can use LEFT() or SUBSTRING()

LEFT( field, LOCATE('.',field)-1 )

SUBSTRING( field, 1, LOCATE('.',field)-1 )
0
 

Author Comment

by:Murphy1992
ID: 40425372
Thanks for responses.

Right outer join was an attempt to get around exact matching ....... wasn't many choices :/

The database is a proprietary database which we cannot access however I can create some external tables linked via ODBC and try your suggestions.  Not ideal but definitely a potential work around.

Thanks
0
 
LVL 13

Expert Comment

by:Koen Van Wielink
ID: 40425389
Paul, just want to check something about your comment. You say "don't use charindex". Is that because it's a Pervasive database? On MS SQL charindex would be the correct choice right?
Also didn't realize that substring isn't a zero based function.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40425494
Sorry, Yes, for Pervasive use LOCATE()

If it was mssql the CHARINDEX() would be used
(and not locate :)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SonarQube on Linux vs Windows 3 27
Querying data from 3 SQL tables 2 32
Application Crash 2 23
Create snapshot on MSSQL 2012 3 18
I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Viewers will learn how the fundamental information of how to create a table.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question