Is there a way in Crystal Reports where I can select the correct record based on multiple rows of a dataset?
I have a contacts table that links to an address table. In the address table there is a field that defines the address type. The address table may contain multiple addresses for the same contact that might be the type of business, home or mailing addresses.
When selecting my dataset I pull multiple records but my report only needs one. How can I select the appropriate address record depending on what records are there? For example if business address is there I want that, if not I want mailing, if not there I want home.
I need to filter these records within Crystal Reports unless I can modify the sql select.
The output of the sql looks like this:
ABC Company, Main Street, Location
ABC Company, First Street, Mailing
ABC Company, Second Street, Business
Your question should include some relevant data, tables schema and desired output. The following should get you started.
SELECT C.ContactId, C.ContactName
COALESCE(BA.Address, MA.Address, HA.Address) AS Address
FROM Contact C
LEFT JOIN Address BA ON BA.ContactId = BA.ContactId AND BA.AddressTypeId = 1 -- your business address type
LEFT JOIN Address MA ON MA.ContactId = MA.ContactId AND MA.AddressTypeId = 2 -- your mail address type
LEFT JOIN Address HA ON HA.ContactId = HA .ContactId AND HA .AddressTypeId = 3 -- your home address type
Related
I have a report that pulls in deceased executives that are tied to a company. The only parameter is the deceased date. The information is displayed in the Details section so that if they were executives in more than 1 company, both companies are listed. I need to add deceased spouses of the LIVING executives. So if John Doe is CEO of ABC Company and his wife Jane passed away in the parameter's time frame, her name should be listed, not John. I've tried a subreport for the spouses, but it won't work with the information being in the details section. The primary table can't be the death table because we need to pull in the spouses of the LIVING executives. I've thought about having two subpreports - one of the executives and one for the spouses, but I'm not sure how to do that. How would you handle this?
Use a UNION ALL View, SP, or Command as the data source for the report.
First Select with regular Company - Exec
UNION ALL
Second Select with Company - Exec - Spouse
If Spouse and Exec are in same table, use that table twice in the 2nd Select and apply an Alias to the 2nd instance.
I am using Crystal Reports. In our tables we have members and clients. Members refer clients to our business. I am trying to display the customer name, and if they have a referring member display the referring members customer name as well. Since they are in the same table how can I do this?
In the scenario below Jake is the client with Mike being the referring member. The sequence number and referring member columns tie them together.
Seq Number --- Customer Name ---------Referring Member
4356 -----------------Mike ----------------------------- 0
7286 ---------------- Jake -------------------------- 4356
enter image description here
In Crystal, Database Expert, bring in the Customer Table table into the report a second time. Give it an Alias of "Member". Join the Customer table to the "Member" table on Customer.Referring Member = Member.Seq Number.
Working with vehicle asset management and I am selecting data based on two statements:
({EQ_MAIN.PROCST_PROC_STATUS} in ["A", "AS", "AT"] and
{EQ_MAIN.DEPT_DEPT_CODE} like "P*" and
{EQ_MAIN.ASSET_TYPE} <> "COMPONENT")
or
({EQ_MAIN.PROCST_PROC_STATUS} in ["TA"] and
{EQ_MAIN.DEPT_TEMP_LOANED_TO} like "P*" and
{EQ_MAIN.ASSET_TYPE} <> "COMPONENT")
Basically, if the Equipment is in status A, AS, or AT and belongs to the departments that start with P, I want it to show on the report. However, the second part of the selection statement accounts for equipment that is temporarily loaned to another department (status TA). The selection statements seem to be working fine.
I have this data grouped by {EQ_MAIN.DEPT_DEPT_CODE}. But I want it to to include any temporarily loaned out equipment under the department group, if the equipment is on temp loan to said department. For example, Car A belongs to department K1234, but is on loan to department P5678. I want Car A to show up under the group for P5678 along with all the other vehicles that belong to P5678. Essentially, whether a piece of eq belongs to a specific department or is simply on loan to said specific department, I want to see them under the same group in Crystal. Thoughts?
I do not believe that a grouping formula is the solution for this scenario. The challenge is based in the recordset. Since there is only one LOANED_TO record per DEPT_CODE, you can go about this a couple of ways.
If this is an option, modify your query or view so that you generate all LOANED_TO records for each DEPT_CODE. This could be achieved by placing a subquery in your FROM clause if using SQL. Then, join your parent table EQ_MAIN to the subquery on a non-unique, general key. Since there is no one-to-one relationship in this scenario, you should get all LOANED_TO records for each DEPT_CODE. This will, however, bloat your recordset and mar performance.
Then, group the report first on {DEPT_CODE} and second on {LOANED_TO}. Use a suppression formula on the second group to hide any {LOANED_TO} Departments that do not match the parent group {DEPT_CODE}.
The more "traditional" Crystal approach is to group on {DEPT_CODE}. Then, add a sub report to a group section. Using the same datasource, move the second chunk of selection criteria (following the OR clause) to the sub report record selection. This will return all {LOANED_TO} records. Add a sub report link between the group {DEPT_CODE} and the sub report {LOANED_TO} dept. This will filter results to just those {LOANED_TO} records related to the main group.
I am using
OS - Windows 7,
technology - progess 4gl.
I have two tables customer and order. I am displaying customer details along with their orders. Each customer may have more then one order. The report should be as below
CUSTOMER:-
CUMTOMER NAME ADDRESS
CUSTOMER1 XYZ
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ASD
2 ASDFGGH
3 FGHJFG /* IT SHOULD REPEAT FOR THE PARTICULAR CUTOMER */
CUSTOMER2 ABC
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ZXC
2 VNVN
3 JJLK
I Think for this we need one-many relationship between customer and order table. I have only customer and order temp-tables for doing this.Can you please tell me How to repeat the loop inside customer and how to link the tables in one-many relationship. Thanks in advance.
you should write a stored procedure and then link that SP with your report.
I don't know why you would need anything more complicated than a join.
Something like:
select * from customer, order where order.custNum = customer.custNum.
Having said that -- you might find this Progress Knowledgebase article relevant. Some versions of Crystal apparently produce SQL that might need to be adjusted:
http://knowledgebase.progress.com/articles/Article/18979
It sounds like you are just having an issue with how it is shown, I would join the table like Tom suggested order.custNum = customer.custNum
but in the Design section I would do the following:
GH1a Customer Name
GH1b Customer Information
GH2 Order Number
Det Order Information
you could also place all of the Customer Information (name, addr, etc) into a formula so that if the customer doesn't have all the data filled in it won't be shown, and won't show a blank line.
I have a table that have 3 columns
id, company and adress
i found a bug today that saved the adress in the company-column and company in the adress-column SOMETIMES, i have corrected the bug and now im trying to put the data in the right places
every adress has a number in it so my guess is that the easiest way is to switch adress and company columns if there is a number in the company-column (if there should be a number in the real company name this wont matter that much :p).
How should i write this in TSQL?
I'm not sure this is right thing to do here but as I can't think of any other alternative this should do it.
Update dbo.MyTable
Set Company = Address,
Address = Company
Where Company like '%[0-9]%'
You can try this: i put a simple protection to avoid the swap if the company adress already contains a number
insert into COMPANY (NAME, ADDRESS)
VALUES ('2 bld d''Italie' , 'CA') ,
('Take 2' , 'anselmo street 234') ,
('Microsoft' , '1 Microsoft Way Redmond'),
('lake street 14' , 'Norton'),
('lake street 17' , 'trendMicro');
SELECT * FROM COMPANY
UPDATE COMPANY set NAME = ADDRESS, ADDRESS = NAME
WHERE NAME like '%[0-9]%' and (ADDRESS not like '%[0-9]%')
SELECT * FROM COMPANY
You could notice that the take 2 line won't be swapped