Solved

Crystal Reports 2011 Table Join

Posted on 2014-11-04
7
126 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 12

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 12

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 12

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now