import data from .txt for reporting purposes - sql

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.

Related

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

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);

Database to Excel charts (or pdf)

Hi guys I have a simple DB that has two fields in it (time and number 1-3), the data needs to be exported and shown in simple charts (horizontal bars from 0 to max time from my DB)? What is the best way to do that?
The easiest was to establish a direct data access from excel to SQL-Server and use Excel's abilities for the graphics.
If you need the data "exported", it is quite easy to get a table as CSV-list. Again this can be opened with Excel directly to do the graphical work there.
Depending on your environment you might think about any reporting tool, obviously the first choice was SSRS or PowerBI, which is part of the box.
You might even use a SELECT * FROM YourTable and just copy-and-paste the full result into Excel.
The main things to think about:
One-time action or regularly
Grade of automatism
Size of data / Count of rows
Location / Access-rights / Linkability of your systems
Existing tools

Order by works inside base but doesn't in runtime report

I've tried to do a report order by date for almost 2 weeks and still no working properly, and I don't know what can I do anymore :(
This sounds like this, I've a report with 5 fields, one of them is invisible, the Last field of the report is called DEVOLUCAO, and I need my report order by that field ascending, that's the problem, I do a query that works properly in database (access), that works properly in preview data of dataset (visual studio 2010), but in run time it doesn't work, I've already modified the sort expressions in tablix, and do it too on each field of report, but all my ideas has gone...
So I'm using this code to select data:
Select idemprestimo, nomeleitor, titulo, saida, devolucao from tbemprestimohistorico order by devolucao asc
So with this query I can make the report, the report is generated but don't order by devolucao asc, and in preview data it works, directly inside the base it works too, but in run time don't...
So, since the thanks for help
Ps* I'm using vb. Net and access and working on windows form
Don't ever use sorting on the recordsource of an Access report. It will be ignored and may even slow down the opening of the report.
Always apply all sorting in the report itself.

How do I get the index of each record displayed on crystal reports?

I'm developing winform application using vb.net. I use crystal report in my application. Now i need to store the index of each record that is displaying in current report into database. Then i create another report which displays the index of all the records. My plan is to read the page number of each record and save them on database. I have a group field in the report. I don't know how to scan one by one record and get appropriate page number. I tried the following code to get the field value but did not work.
msgbox(rpt.DataDefinition.FormulaFields("name").Text)
It displayed the formula of that field.
I don't know in which order the records fetched using following.
msgbox(rpt.rows(0).item(0))
Please Help me out....
The way your question reads, it sounds like you're trying to generate an "index" for the order records appear in a report and store that index in a database for use in another report. I am not clear at all what you're trying to do with the page number.
In any case, I need to make something clear: the definition of the report (which you're accessing in your code sample) only represents where data will go when the report is formatted - it is not the actual data itself.
At the most basic level, Crystal Reports takes data out of a database and formats it nicely for you on pages. Rather than trying to take data out of a database, put it into a report, then try to read that report to put it back in a database to make another report, why not just do all your data manipulation at the database level itself before going to a report in the first place?
If you really must have that first report, the easiest option you'll have for getting at the formatted data is to export it to excel and access it programmatically through an Excel API - Crystal Reports doesn't have an API for getting at your formatted data (including things like generated page numbers, whatever you're trying to do with them).
You are trying to break few basic rules. For example a report should never change the data. The right way is to handle data processing in a stored procedure or command and to call the report in a separate process. In such way you will be able to control the data change and data visualization separately.
P.S. You probably mean "Identifier" not "Index"

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.