Solved

Crystal Reports 2011 Table Join

Posted on 2014-11-04
7
128 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

914 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

17 Experts available now in Live!

Get 1:1 Help Now