Reporting on multiple tables independently in Crystal Reports 11 - crystal-reports

I am using Crystal Reports Developer Studio to create a report that reports on two different tables, let them be "ATable" and "BTable". For my simplest task, I would like to report the count of each table by using Total Running Fields. I created one for ATable (Called ATableTRF) and when I post it on my report this is what happens:
1) The SQL Query (Show SQL Query) shows:
SELECT "ATABLE"."ATABLE_KEY"
FROM "DB"."ATABLE" "ATABLE"
2) The total records read is the number of records in ATable.
3) The number I get is correct (total records in ATable).
Same goes for BTableTRF, if I remove ATableTRF I get:
1) The SQL Query (Show SQL Query) shows:
SELECT "BTABLE"."BTABLE_KEY"
FROM "DB"."BTABLE" "BTABLE"
2) The total records read is the number of records in BTable.
3) The number I get is correct (total records in BTable).
The problems starts when I just put both fields on the reports. What happens then is that I get the two queries one after another (since the tables are not linked in crystal reports):
SELECT "ATABLE"."ATABLE_KEY"
FROM "DB"."ATABLE" "ATABLE"
SELECT "BTABLE"."BTABLE_KEY"
FROM "DB"."BTABLE" "BTABLE"
And the number of record read is far larger than each of the tables - it doesn't stop. I would verify it's count(ATable)xcount(BTable) but that would exceed my computer's limitation (probably - one is around 300k rows the other around 900k rows).
I would just like to report the count of the two tables. No interaction is needed - but crystal somehow enforces an interaction.
Can anyone help with that?
Thanks!

Unless there is some join describing the two tables' relationship, then the result will be a Cartesian product. Try just using two subqueries, either via a SQL Command or as individual SQL expressions, to get the row counts. Ex:
select count(distinct ATABLE_KEY) from ATABLE
If you're not interested in anything else in these tables aside from the row counts, then there's no reason to bring all those rows into Crystal - better to do the heavy lifting on the RDBMS.

You could UNION the two queries. This would give you one record set containing rows from each query once.

Related

SQLite query not working when trying to run the same query in postgresql

I have a database of users purchase/sell of stocks and need to retrieve the data by summing all the shares for that specific user.
Ex: If I choose user_id = 7, it should return two rows, one with TESLA and one with Apple with the sums of the shares.
Database:
SQL queries I've tried include:
SELECT name,symbol,name,price,total, SUM(shares)
FROM symbol
WHERE user_id=7
GROUP BY name,symbol,name,price,total
Returns: but it should just be two rows
Your issue is your grouping.
Consider the uniqueness of what you are grouping by and that is how many rows you will get returned.
With your where clause and grouping by name,symbol,name,price,total there are three unique rows.
Remove the price and total columns from the grouping and you will get your desired two rows, or include them in your query as sum'd columns.
eg.
SELECT name,symbol,name,SUM(shares)
FROM symbol
WHERE user_id=7
GROUP BY name,symbol,name

Tableau is counting too many records

I am new to tableau and not sure what information is needed to answer this question.
I have set up my Data Source with multiple tables and joins. All of the joins are inner joins.
I am trying to get a count of records from one of my tables.
The table has 112,000 records but tableau is returning a count of 12 million
One of your joins is multiplying the record count by 10. I suggest removing the joins 1 by 1 until you pinpoint the cause.

Crystal Reports Record Filtering using and

Currently I have a crystal report that only shows orders which included a "Storm Door" OR a "Sunroom Component". However I would like it to only show orders that include BOTH "Storm Door" AND "Sunroom Component" within a order. Any suggestions on how the code for this might look?
I think you have answered your own question - If you want the report to retrieve records where BOTH products were ordered, you would use an AND statement - {Categories.Description} = "Storm Doors" and {Categories.Description} = BetterView Sunroom Compnents". However, the issue with duplicate records sounds like a problem with the design of the report. You could try a few things
Look at the table joins and verify they are setup correctly; if you have a 'one to many' join setup, you may be retrieving multiple rows for each record. If you joined Customer to Orders on the Customer_ID, you would get every single order for each customer, etc.
Click Database > Select Distinct Records - Depending on how your report is configured and which fields you are displaying, this may remove the undesired duplicates.
Change your grouping order - Instead of grouping by Category (Storm door, Subroom), group by Customer and then count the number of orders or use an aggregate function to give you the information you need.

See length (count) of query results in workbench

I just started using MySQL Workbench (6.1). The default limit for queries is 1,000 and that's fine I want to keep that.
But the results from the action output message will therefore always say "1000 rows returned".
Is there a setting to see the number of records that would be returned in the query had their been no limit? For sanity checking query results?
I know this is late by a few years, but I think you're asking for a way to see total row count in the bottom of the results pane, like in SQL Server. In SQL Server, you would also go in the messages pane and it would say how many rows were returned. I was actually looking for exactly what you were asking for as well, and seems like there is no way to find that. If you have an ID in your table that is just numeric and is in numeric order, you could order by ID desc and look at the biggest number there. That is what I've decided to do.
The result is not always "1000 rows returned". If there are less records than that you will get the actual count. If you want to know the total number of rows in a table do a select count(*) from table. Alternatively, you can switch off the automatic limit and have all records returned by MySQL Workbench, but that can be time + memory consuming for large tables.
I think removing the row limit will help. By default, MySQL workbench will limit the result set to 1000 rows but you can always disable the limit. Check out https://superuser.com/questions/240291/how-to-remove-1000-row-limit-in-mysql-workbench-queries on how to do that.
You can run a second query to check that
select count(*) from (your original query) as t;
this will return the total rows in actual result.
You can use the SQL count function. It returns the count of the total number of rows a query returns.
A sample query:
select count(*) from tableName where field1 = value1
In workbench, in the dropdown menu at the top, set it to dont limit Then run the query to extract data from table Then under the output pane below, the total count of the query results will be displayed in the message column

How to filter in records from one dataset to another?

I am developing an SSRS 2008 report. I created one dataset to give me the records I want. I also created a different dataset that determines access based on security profiles of the person running the report. What I want to do now is join the results of this second dataset with those of the first dataset in T-SQL. So I would like to perform this join within the T-sql sproc for the first dataset. How do I do this? Note that in most cases the results of the second (security) dataset is more than one record.
Are both datasets coming from the same database? You can probably wrap this logic in a stored procedure instead.