Crystal Report Gives me a Different SQL Result - crystal-reports

I am getting a different result in CR. I got the right result when I tried to run the query in SQL Server
here is the example of my situation
TB1
TB2
what I am trying to achieve is like this
BUT the CR's result is like this
here is my query:
SELECT * FROM TB1 tb1 LEFT JOIN TB2 tb2 WHERE tb1.ControlNo='IDU 2005.0001' AND tb2.Type = 'Applicant'

This can't be the SQL statement used in the Crystal report.
Are you using a Command as the data source in the report? If so, please show the command in your question.
If you are not using a Command, please show the table joins and the record selection formula.
Most likely, you are not using a Command and the record selection formula in the report design is simply wrong.

Related

ERPNext: Join multiple tables using script report

Anyone know what is the ORM function for joining multiple db tables in ERPNext?
I need query result from 2 DB tables join using script report
*I don't need query report answer since i already have it. I only looking for an example do it using script report
Frappe currently doesn't have ORM support for joining tables. You might have to use frappe.db.sql for the time being.
data = frappe.db.sql(
"""
select tb1.name from tabTable1 as tb1
left join tabTable2 as tb2 on tb1.name = tb2.employee_name;
"""
);
return data

Add Heading to a group of columns in Oracle SQL

Oracle 11g. Oracle Apex 5.1
I need to Merge the columns without merging the data and Add a column heading in Oracle Apex Interactive Report.
For Example
I have a table like this:
I want the table output like this:
How can I achieve the output in Report Select Statement?
If I am using below query in Oracle Apex Interactive Report:
TITLE LEFT ' amount_column Quantity_column'
SELECT Date, Amount1, Amount2, Amount3, Quantity1, Quantity2
FROM table_name;
I am getting error as: ORA-20001: Query must begin with SELECT or WITH.
In oracle Apex 5.1 we can create such groups in Interactive Grid(IG).
To create a group, steps are:
Go to Attribute of IG -> create Group -> add a name to group.
To assign a group on column, steps are:
go to particular column(s) name -> under layout property -> select group name
Save and run the page and it will work.
If you are running the query to get a SQL/Plus style textual output (using Crtl-F5 / run-as-script within SQL Developer) then you can use the commands for formatting SQL*Plus reports such as COLUMN and TTITLE to make it appear like your desired result:
Something like (untested):
COLUMN "Date" FORMAT A9
COLUMN Amount1 FORMAT 9999.99
COLUMN Amount2 FORMAT 9999.99
COLUMN Amount3 FORMAT 9999.99
COLUMN Quantity1 FORMAT 999999999
COLUMN Quantity2 FORMAT 999999999
TTITLE LEFT ' Amount column Quantity Column'
SELECT "Date", Amount1, Amount2, Amount3, Quantity1, Quantity2
FROM table_name;
If you want to do it in the grid (using F5 to run the query within SQL Developer) then you are out of luck and it is not possible.

Pivot column in SSRS

I have report where I am using that stored procedure to create a report using SSRS. The report currently show data like below (it has more additional columns) :
What I want is at the backend (stored procedure level or in SSRS) want the filter the data for product_type A only, but I want to show the amount associated with the product type F in a new column as below:
Can anyone help to achieve this please?
A simple LEFT JOIN with the same table will do the work
SELECT t1.INVOICE_NO,t1.PRODUCT_TYPE,t1.AMOUNT,t2.AMOUNT AS FEE_AMOUNT
FROM tbl t1
LEFT JOIN tbl t2 ON t1.INVOICE_NO=t2.INVOICE_NO AND t2.PRODUCT_TYPE='F'
WHERE t1.PRODUCT_TYPE='A'
you can also use matrix to achieve the same on ssrs side. In this case your trade off is none i.e. doing pivot on sql side and then rendering the data in ssrs table VS leaving data as is in sql and using matrix to pivot the data.

Crystal Reports table linking with TRIM / OR

This is a two part question.
The below needs to be done WITHOUT using Command
PART-1
How to link tables that have a 'OR' in it. Something like:
select * from TableA inner join TableB
on TableA.col1 = TableB.col1 OR TableA.col2 = TableB.col2
PART-2
How to link tables that have a trim in it. Something like
select * from TableA inner join TableB
on TRIM(TableA.col1) = TRIM(TableB.col1)
Please note that both the above needs to be done without COMMAND.
how can it be done ?
Thanks !
You can link both the fields in database expert and you can write your selection in select expert as per your requirement.
For part 2 just link the fields and trim in crystal report formulas

In SSRS, why do I get the error "item with same key has already been added" , when I'm making a new report?

I'm getting the following error in SSRS:
An error occurred while the query design method was being saved.
An item with the same key has already been added
What does an "item" denote, though? I even tried editing the RDL and deleting all references to the Stored Procedure I need to use called prc_RPT_Select_BI_Completes_Data_View.
Could this possibly have to do with the fact that the Stored Procedure uses Dynamic SQL (the N' notation)?
In the stored procedure I have:
SET #SQL += N'
SELECT bi.SupplierID as ''Supplier ID''
,bi.SupplierName as ''Supplier Name''
,bi.PID as ''PID''
,bi.RespondentID as ''Respondent ID''
,lk_slt.Name as ''Entry Link Type''
,ts.SurveyNumber as ''Initial Survey ID'''
It appears that SSRS has an issue(at leastin version 2008) - I'm studying this website that explains it
Where it says if you have two columns(from 2 diff. tables) with the same name, then it'll cause that problem.
From source:
SELECT a.Field1, a.Field2, a.Field3, b.Field1, b.field99 FROM TableA a
JOIN TableB b on a.Field1 = b.Field1
SQL handled it just fine, since I had prefixed each with an alias
(table) name. But SSRS uses only the column name as the key, not table
+ column, so it was choking.
The fix was easy, either rename the second column, i.e. b.Field1 AS
Field01 or just omit the field all together, which is what I did.
I face the same issue. After debug I fixed the same. if the column name in your SQL query has multiple times then this issue occur. Hence use alias in SQL query to differ the column name.
Ex:
The below query will work proper in sql query but create issue in SSRS report:
Select P.ID, P.FirstName, P.LastName, D.ID, D.City, D.Area, D.Address
From PersonalDetails P
Left Join CommunicationDetails D On P.ID = D.PersonalDetailsID
Reason : ID has mentioned twice (Multiple Times)
Correct Query:
Select P.ID As PersonalDetailsID, P.FirstName, P.LastName, D.ID, D.City, D.Area, D.Address
From PersonalDetails P
Left Join CommunicationDetails D On P.ID = D.PersonalDetailsID
I have experience this issue in past. Based on that I can say that generally we get this issue if your dataset has multiple fieldnames that points to same field source.
Take a look into following posts for detail error description
https://bi-rootdata.blogspot.com/2012/09/an-error-occurred-during-report.html
https://bi-rootdata.blogspot.com/2012/09/an-item-with-same-key-has-already-been.html
In your case, you should check your all field names returned by Sp prc_RPT_Select_BI_Completes_Data_View and make sure that all fields has unique name.
I had the same error in a report query. I had columns from different tables with the same name and the prefix for each table (eg: select a.description, b.description, c.description) that runs ok in Oracle, but for the report you must have an unique alias for each column so simply add alias to the fields with the same name (select a.description a_description, b.description b_description and so on)
Sorry, it is a response to an old thread, but might still be useful.
In addition to above responses,
This generally happens when two columns with same name, even from different tables are included in the same query.
for example if we joining two tables city and state where tables have column name
e.g. city.name and state.name.
when such a query is added to the dataset, SSRS removes the table name or the table alias and only keeps the name, whih eventually appears twice in the query and errors as duplicate key.
The best way to avoid it is to use alias such as calling the column names
city.name as c_name
state.name as s_name.
This will resolve the issue.
I got this error message with vs2015 enterprise, ssdt 14.1.xxx, ssrs. For me I think it was something different than described above with a 2 column, same name problem. I added this report, then deleted the report, then when I tried to add the query back in the ssrs wizard I got this message, " An error occurred while the query design method was being saved :invalid object name: tablename" . where tablename was the table on the query the wizard was reading. I tried cleaning the project, I tried rebuilding the project. In my opinion Microsoft isn't completing cleaning out the report when you delete it and as long as you try to add the original query back it won't add. The way I was able to fix it was to create the ssrs report in a whole new project (obviously nothing wrong with the query) and save it off to the side. Then I reopened my original ssrs project, right clicked on Reports, then Add, then add Existing Item. The report added back in just fine with no name conflict.
I just got this error and i came to know that it is about the local variable alias
at the end of the stored procedure i had like
select #localvariable1,#localvariable2
it was working fine in sql but when i ran this in ssrs
it was always throwing error but after I gave alias it is fixed
select #localvariable1 as A,#localvariable2 as B
SSRS will not accept duplicated columns so ensure that your query or store procedure is returning unique column names.
If you are using SPs and if the sps have multiple Select statements (within if conditions) all those selects needs to be handled with unique field names.