SQL query to create a list of values to use in a drop down list - sql

Relative newbie to SQL here and I need help writing a query.
We use an application that uses SAP Crystal reports as it's reporting tool. In the application users are able to select the run parameters for the report, and these parameters are then passed to the report and inserted into the SQL query used to create the report.
For some reports we want to let the users decide how they want to group the reports using 3 options (Account, Manager and Broker) rather than having 3 versions of the report.
To avoid typing errors, I would to provide the 3 options as a list, which would appear in a drop down. Is there a way to do this in a query without creating records in a table?
Thank you

Simply create a parameter and enter the 3 values in the list of default values.

Here is a link to a web page explaining the process step-by-step: https://www.rklesolutions.com/blog/crystal-reports-p4

Sounds like you simply need to populate a dropDown control with a list of static values. But you didn't mention your programming language. Assuming this is C#:
ListItem item = new ListItem(itemText, itemValue);
dropdownlist.Items.Add(item);

Related

SSRS Report, shared layout, using different data sets

We need to create several reports but they all have the same exact layout. Rather than creating many reports, is it possible to create a single report that can conditionally be populated by different sets of data?
For example, say the report is a simple list of customer names and addresses. I would like to have a parameter that asks for a customer type. A second drop down parameter list would only show customer subtypes directly related to the parent customer type. Can a parameter drop down be filtered based upon a selection in another parameter drop down?
What other ways can I manage a single report layout but populate with different sets of data based on parameters?
is it possible to create a single report that can conditionally be
populated by different sets of data?
Yes, it is possible as long as the multiple data you use fits the structure of your report. Using parameters you can populate your report with different data.
Can a parameter drop down be filtered based upon a selection in
another parameter drop down?
Yes, A parameter can be populated based on other parameter selection. There are a lot of resources in the web that ilustrate how to achieve that functionality. Give a try and if you get stuck we are here.
What other ways can I manage a single report layout but populate with
different sets of data based on parameters?
You can select the data in your report by using multiple parameters and a single dataset. Then using SQL statements and parameters you can filter from where clause or create a flow in multiple select statements using T-SQL. Something like
IF #my_param = 1
BEGIN
select ...
END
ELSE
BEGIN
select ...
END
Let me know if this helps you.

How to execute dynamic query in anypoint studio?

currently I am trying to create one application using Any point studio. But stuck here...
I am having two select query to fetch the data from two different tables of a single database and according to the request it will decide from which table the data will be fetched.
I'm able to create the dynamic query which will take the dynamic table name and column name. But, I wanted to take two different query. As the column name in the where clause is different for both.
please help me out...
Thanks
You should be able to use MEL expressions in the database connector by choosing "Dynamic" type select query. So you only have to put the correct clause on a string variable and reference it on the connector.
Anyway, I would not try that approach. I would place a "choose" flow control and two database connectors and decide which of them use base on your condition. I would use "Parametrized" type select query, it is more secure than using "Dynamic".
Best regards,
José

import data from .txt for reporting purposes

I am running a query in Report builder that uses order numbers (approx. 100). Currently they are fixed and I have to change them each time. Is there a way that I can import those numbers to Report Builder in .txt and then run the report.
The query is like the following:
Select * from purchase p
where p.order in ('15642','1245','623565')
This is a simple query but my query has lots of joins
If not, how can I rewrite this report so that users can choose their own order number?
Does Cyrstal report have that ability?
Making a .Net/C# application Tool and export results to EXCEL??
Suggestions would be appreciated!
Yes, Crystal Reports can import from textfiles (At least Crystal Reports XI that I'm using), although that functionality might not be installed by default.
Create a new connection, choose "Access/Excel (DAO)". In the dialog that comes up, select "Text" as database type. By default the first line of the text file is supposed to be headers. I don't know if it is possible to change this behaviour.
As for letting users choose the order number at runtime that is precicely what parameters are for. Create a parameter and call it like {CR_test_txt.TEST0001} = {?myParameter} in the field selection expert. Depending on your report and advanced runtime options you want you might have to parse the parameter before using it.

Substitute one table for another at runtime

I have 9 tables with state information in them. They all have the same field names. I have a Crystal Report that is based on one of them. I want the user to be able to select a state and change the Crystal Report to use that table instead of the one it was based on.I mean when user select text in combo box and then click on "OK" then report show (using only one rpt for all the tables of same fields).
How do I do that in VB.Net?
Could you base the Report on a Stored Procedure and pass in a parameter so the Stored Procedure knows which table you want the data from?
I remember trying to get a Crystal Report (v2005) to switch database source from the one it was designed against and that wasn't easy - every table had the connection details in it if I recall correctly! (maybe changing tables is easier though)
It's not easier but if the tables have the same structure you should be able to do it. But you should create a new Document for it and call SetDataSource for your new table. After this you can set the document as ReportSource to your viewer.

Dynamic SSRS report

I had a problem in creating the Dynamic report in SSRS. My problem is:
In a table I have stored SQL scripts with the column SQLScripts. If you execute these SQL scripts you get different number of columns for each script.
My problem is, I have one report with buttons of these scripts, for example test1, test2...like that. If you press test1 button this should take the test one SQL script and should display the report with appropiate columns in that sqlscripts.
I can't create individual reports for each test report, they are plenty. Are there any options for me to solve this problem...
The only way I've been able to get this to work sofar is:
Each report has 2 datasets.
ReportData
DataHeaders
The "DataHeaders" need to have the proper name of the datafields in "ReportData". Be careful since SSRS replaces blanks and special characters with "_"
Now, create a table (or matrix) and drag the DataHeaders as the Columns of your report. (This should be a grouped column). If you run it at this point, you'll see all your columns without any data. Now comes the magic:
Create another report that takes a "DataField" parameter. Create another table or matrix within this report and set it's dataset property to be "ReportData". In the DATA cell for the table, set it to the expression =Fields(Parameters!DataField.Value).Value
Now go back to your first report. Right click and insert a subreport. Right click on the subreport and select "Subreport Properties". Under general, select the second report you created to be used as the subreport. Under parameters, select the DataField parameter and set its value to something like =Fields!DataField.Value
In my case I did some formatting in this expression to fix the above mentioned issue with spaces and special characters, since my stored procedure was initially used in ASP.NET and this was just a proof of concept.
Also in my experience the performance isn't great. In fact it was kinda slow, though I haven't had a chance to switch it to use a shared dataset, which I suspect would help a bit. Please let me know if you find a better solution.
I have not found a way to do this completely dynamically. Here is a similar question with some possible solutions:
How do i represent an unknown number of columns in SSRS?
You basically need to create a 'master dataset' from the other Datasets that are based on your multitude of SQL scripts first.The master dataset should contain the data to be presented in it's most simplistic form, i.e. in a simple list format.
Finally, go to the toolbar in SSRS and drag a 'Matrix' into the report. A Matrix table acts similar to a pivot table in Excel or a CrossTab query in Access that will display whatever's in the Dataset.