How to Generate SubReport in crystal report with SQL Query? - sql

I am Having a Report Which has to generate from Two different where Clauses.
**Condidtion 1**
Select * from Table1 where Name="ABC"
**Condition2**
Select * from Table1 where city="LA"
In above mentioned case, the condition two should appear in sub report part
Please remember the Data is populatinf from same table and in same crystal report
Condition 2 Will be in subreport

Create a Datasoruce and name the subreport as sub1 or anything paste the following code
rptdoc.Subreports("sub1").SetDataSource(dv1)

Related

Change in where clause only for 100's of different report, merge it into only one

I have to create and subscribe several SSRS reports based on one single change in the same SQL query.
e.g
SELECT * FROM TABLE1 WHERE value IN (123,456,789)
Report based on the above query should go to the emailaddress1#test.com
Similarly
SELECT * FROM TABLE1 WHERE value IN (111,222,333) - emailaddress2#test.com
SELECT * FROM TABLE1 WHERE value IN (444,555,666) - emailaddress3#test.com
SELECT * FROM TABLE1 WHERE value IN (777,888,999) - emailaddress4#test.com
the change is only in value for every report, and i have to send every report to different email address.
Is there any way to do this other than creating 100's of separate reports ?
You can parameterize the report so that you only have one report, and create a separate subscription with the parameters values for each email address.

SSRS Dropdown for column items

I've built a SSRS report using a SQL query for the Dataset1. I'm trying to build a parameter that gives the users a dropdown list. I ended up creating a Dataset2 to get distinct values for the parameter Label and then use Dataset1 for the actual value (allowing for multiple values).
EDITING PER Request:
Dataset1 query:
SELECT vu_SOPWork_HistoryUnion.Type
,vu_SOPWork_HistoryUnion.SOPTYPE
,vu_SOPWork_HistoryUnion.SOPNUMBE
,vu_SOPWork_HistoryUnion.Date_Document
,vu_SOPWork_HistoryUnion.ExtendedPrice
,IV00101.ITEMNMBR
,IV00101.USCATVLS_2 AS Family
,IV00101.USCATVLS_3 AS Product
,vu_SOPWork_HistoryUnion.VoidStatus
,RM00101.CUSTCLAS
,GL00100.MNACSGMT
,vu_SOPWork_HistoryUnion.BillTo_CustNum
,vu_SOPWork_HistoryUnion.BillTo_CustName
,vu_SOPWork_HistoryUnion.sales_territory
,vu_SOPWork_HistoryUnion.ITEMDESC
FROM (
(
test.dbo.vu_SOPWork_HistoryUnion vu_SOPWork_HistoryUnion INNER JOIN test.dbo.IV00101 IV00101 ON vu_SOPWork_HistoryUnion.ITEMNMBR = IV00101.ITEMNMBR
) INNER JOIN test.dbo.RM00101 RM00101 ON vu_SOPWork_HistoryUnion.BillTo_CustNum = RM00101.CUSTNMBR
)
INNER JOIN test.dbo.GL00100 GL00100 ON IV00101.IVSLSIDX = GL00100.ACTINDX
Dataset2 Query:
SELECT DISTINCT IV00101.USCATVLS_2 AS FamilyNames
FROM test.dbo.IV00101
I would like to use the Dataset2 "FamilyNames" as the label options against Dataset1 "Family" values. Dataset2 gets the distinct values that I want to put in the drop down for the user to choose and then receive all rows that has that value in Dataset1 "Family". I'm an expert on not giving enough information. Hope this helps you help me. Thanks.
OK, do the following..
Create DataSet1 with the query as you have it now but append the following to the end of the query
WHERE USCATVLS_2 IN(#Family)
When you do this, the #Family parameter will be created automatically in your report, we'll get back to this later.
Create another dataset called Dataset2 (or a more sensible name like 'families' in this case) with the following simple query.
SELECT DISTINCT USCATVLS_2 FROM test.dbo.IV00101 ORDER BY USCATVLS_2
Edit the #Family parameter:
Set it to multi-value
Change the available values to be a query
Select your 2nd dataset as the datasource
Choose USCATVLS_2 as both the labels and values.
Create your report as normal with the tablix/matrix based on Dataset1.
Notes:
A few other things you might want to consider, but not required.
If a list of family names with some kind of ID is available in your database then I suggest you use that for your parameter list, you would also then have to edit the query in dataset1 to match. Remember that the parameter will contain whatever is in the column of the query that you chose as the value column in the dataset that populates the parameter list
Consider using aliases for table names in your queries rather than the full table names all the time, it makes the code more concise and easier to read.
Name your datasets according to what they contain or do, e.g. I would call Dataset2 'Families' or something similar as that is what it contains. When your reports get more complex it will make them easier to understand.

how to pass a parameter in Crystal Reports?

I have a problem in Crystal reports 11. Because it has limitation to showing the information in dynamic reports and I have a huge list of customer, I want to write a query and ask the first letter of the customer name. If for example, it starts with A, just show the A customers.
this is my query:
select distinct bill_to_code
from TLORDER
where left(BILL_TO_CODE ,1 ) = ?
And CURRENT_STATUS <> 'CANCL'
AND LEFT(BILL_NUMBER , 1 ) NOT IN ('M','U','T','K')
but when I copy this to crystal reports and create a parameter , I get an error
Failed to retrieve data from the database
I should mention that I have another sql query in this report .
It is best to use Stored Procedure when trying to pass a parameter. How to create SP. Then used the SP for your report.

Dynamic SQL queries as parameter

I need a Report where a user has to choose 2 parameters. The first parameter contains the years (2017, 2016...), and the second one contains the ID process. Depending on the process that the user chooses, the SQL statement will be one or another. The parameter year is part of the WHERE clause of the SQL contained in the second parameter.
So I have this report with 2 parameters (param_year, Indicador). Query parameter is done using a table datasource, where the IDs column contains the SQL sentences and the Values column contains the text the user must select.
So what I'm doing next is to set ${Indicador} as the SQL statement in the JDBC connection that I have done to the Database. This is reporting me an SQL error
"Failed at query: ${Indicador}.
Any suggestions will be appreciated. Thanks in advance.
Another option is to create multiple datasources in your Master/sub report, then select appropriate datasource using PRD expression on Master/sub Report -> Attributes -> query -> name attribute.
More detailed explanation:
Create a query (I mean a query as a PRD object, which uses the PRD datasource) for every SQL string you need and move the SQL strings from the parameter table into Report Designer queries definitions.
Replace the SQL strings in your parameter table with names of corresponding queries, e.g:
Use the value of your parameter (which should be equal to the PRD query name) as value for Master/sub Report -> Attributes -> query -> name attribute:
You need Pentaho Data Integration to do this kind of dynamic query
If the table structure (output columns) for both queries is the same, you could put them together into one big SQL statement with UNION ALL and put in each query "WHERE ${Indicador} = ValueToRunThisQuery".
The optimizer should be smart enough to know the not-selected subquery is going to return zero rows and not even run it. You can supply a few null columns if one query has fewer columns, but the data types have to be the same for filled columns.
If the output table structure is different between the two queries they should be in different data sources, or even reports.
SELECT ID, BLA, BLA, BLA, ONLY_IN_A
FROM TABLE A
WHERE ${Indicador} = "S010"
UNION ALL
SELECT ID, BLA, BLA, BLA, NULL
FROM TABLE B
WHERE ${Indicador} = "S020"

db2 sql query in excel

I have a number of very simple queries that I run for others on my team and am placing them in Excel so that the end user can just execute the query themselves by opening the spreadsheet.
I'm currently using an ODBC driver to connect to the DB2 server.
All queries work fine but one is giving me a headache in getting it to work correct in Excel.
One of the queries has a where statement that equals a different value depending on the situtation.
ex.
SELECT *
FROM TABLE1 T1
WHERE T1.T1_ID = 859745
What I would like is to set it up so that the query runs like the following. Is it possible to do this through a variable somehow?
SELECT *
FROM TABLE1 T1
WHERE T1.T1_ID = "USER ENTERED VALUE FROM COLUMN A ROW 1 IN THE EXCEL SHEET"
I'm assuming you're using Microsoft Query. First add a parameter to the query. Then you can customize your parameter to choose an excel cell an the input for the paramter