Two tables in one Crystal Report - sql-server

I have 2 database tables (MSSQL SERVER) which are CM (Name of Table 1) and REM (Name of Table 2). Is it possible to make it in Crystal Reports just like in the below image?

Using subreports does not gives you the ability you to use common columns, so you must figure out how to use ONE select statement from database to report.
From your snapshot it seems that your tables have 6 common columns (Control,ClientName,DateReceived,RequiredDocs,UploadStatus,Remarks) which you wish to show, and the first 3 of them are used for grouping. So you could use UNION between two SELECT of these 6 columns of your two tables and then implement the grouping in your report designer.
e.g
"SELECT
Control,ClientName,DateReceived,RequiredDocs,UploadStatus,Remarks
FROM CM
UNION
SELECT
Control,ClientName,DateReceived,RequiredDocs,UploadStatus,Remarks
FROM REM"

Related

Automatically produce aliases for all columns in SELECT statement

I'm using Microsoft Query to pull data from MS SQL Server to Excel. Many of my tables have the same column names, for example:
[task].[active]
[user].[active]
[task].[name]
[user].[name]
When I pivot in Excel, only the column names are shown. A pivot filter might have multiple fields called "active" which is very confusing.
I'd like to alias every column with the table name it's from, so that in the filter it would say "task_active" and "user_active". My Excel SELECT statement would be:
SELECT active AS task_active, name AS task_name FROM task...
Is there a quick way to prepend the table name to an alias using a formatting tool? I have Apex SQL Refactor, and Notepad++ but I haven't found a way to do this without having to manually type all of the column names again.
If you populate resultset to datatable then datatable to excel then it will automatically change duplicate column name to col1,col2 etc.
This is not your requirement.you want it to be specific.
Method 1 . Create temp table with desire column name
Insert the result in #temp table
Return #temp table result set
Method 2 : Use dynamic query.
Wht your real query look like ?

Concatenate two more tables in power bi

I have 3 tables in power bi e.g
Table1
name
Fan_count
connections.likes.id
connections.likes.name
connections.post.id
connections.post.name
and so on
Table2
name
Fan_count
connections.likes.id
connections.likes.name
connections.post.id
connections.post.name
and so on
Table3
name
Fan_count
connections.likes.id
connections.likes.name
connections.post.id
connections.post.name
and so on
for further kindly check attached power bi file
where i have 3 tables and all have same column name so i want to concatenate
these tables .. how i do this
check file
https://www.dropbox.com/s/zxoyqr3le3qgdlc/social%20media.pbix?dl=0
You can use Combine -> Append Queries -> Append Queries as New to combine these tables into one:
This will make a new table, which will contain all rows from your source tables. In the dialog shown, select Three or more tables option and add your tables to the list:

How to show data in column in SSRS

I'm using SSRS for my reporting, my reporting solution is in Visual Studio 2008 Business Intelligence Development Studio.
I have a report in which the data should be displayed in this format.
I have added a Column Group in my table which is having the values of Customer Name and details, the data is coming fine in the vertical format i.e column after column.
My Issue :
There should be only three columns in each row, after three records the next row should begin and again not more than three records should be displayed as shown in the image above.
My attempts :
I tried to add a row group and in that gave the expression
= Ceiling(Fields!Row_Count.Value/3)
here Row_Count is a field which is coming from my query which holds the serial number of the records.
My SQl Query
SELECT Row_Number() over(order by table_ID) AS Row_Count, Field_1,Field_2 from MyTable
In my Column group i have Customer Name and in my Row Group i have other details of the customer. The data is getting populated column wise but the issue is its not breaking the current row after three records.
Below is my table of report.
You were on the right track. Say you have data like this:
I have created a tablix like this:
The Row Group expression is:
=Ceiling(Fields!Row_Count.Value / 3)
This works together with the Column Group expression to split over three columns:
=(Fields!Row_Count.Value - 1) Mod 3
The other thing to note compared to your tablix is that CustomerName is not in a table header row, but rather there are two row header rows, one for CustomerName and one for Details.
This is looking OK to me, obviously you can format to taste:

Simple SQL approach to transform columns into rows (SQL Server 2005 or 2008)

On SQL Server, executing the following SQL Statement:
SELECT 1,2,3
will return
(no column name) (no column name) (no column name)
1 2 3
Note that the columns don't have names and the number of columns is not definite (it can have 1 column or it can also have > 100 columns).
My question is - Does anybody know of a simple approach so I can get the following result:
(no column name)
1
2
3
What I'm really trying to do is come up with a SQL similar to the one below. I wish I could execute it as it is but of course we know that the Select 1,2,3 won't work, we have to somehow transform that into a table with the values in each row.
SELECT *
FROM NORTHWIND.DBO.CUSTOMERS
WHERE EMPLOYEEID IN (*Select 1,2,3*); -- *Select 1,2,3 will not work
Currently I'm thinking of creating a user defined function that returns a table by iterating through each column and dynamically creating multiple SQL statements combined by UNION similar to: SELECT 1 Col1 UNION SELECT 2 UNION SELECT 3. I'm not a fan of dynamic SQL and looping procedures in my queries as it can be expensive to process especially for an application with expected usage of 1000+ per minute. Also, there is that concern for SQL Injection Attacks with Dynamic SQL when I start using strings instead of integer values. I'm also trying to avoid temporary tables as it can even be more expensive to process.
Any ideas? Can we use UNPIVOT without the need for looping through the indefinite number of columns and dynamically creating the SQL text to execute it and transform the columnar values into rows? What about Common Table Expressions?
Get rid of the select and just specify a list of values:
SELECT * FROM NORTHWIND.DBO.CUSTOMERS
WHERE EMPLOYEEID IN (1,2,3);

Questions about Views

I support SQL Servers 2000 thru 2008R2 (all Standard Edition).
Question 1
Please consider the following hypothetical situation. Let's say you have a 5 table view, with the tables inner joined. Let's further assume that I am pulling 10 fields from each table, so I have a View with a total of 50 fields in it. If I selected only 2 fields from the view (one in each of two of the tables), would that query be slower than the equivalent table join script assuming you had all the same tables and joins?
Question 2
What if I created a generic view with a script like this:
Create View SomeView
AS
select * from SomeTable
Go
These tables have fields added to them fairly regularly. Each time I add a field to "SomeTable" the view would automatically work, correct? Is this appreciably slower
if I SomeTable had 50 fields and I selected two of them from the generic view? If I select two fields from the Select * view, will it only query for those fields?
Question 3
If I create a view like the following
Create View Blah
AS
select (some fields)
from TableA join TableB on TableA.Blah = TableB.Blah
Go
Then I use the view like this:
Select (some fields) from dbo.Blah where SomeDate >= '1/1/2008'
Will I lose any performance? Will the optimizer actually only pull view records that apply or will it pull all and then sub select the result set?
TIA.
Each time I add a field to "SomeTable" the view would automatically work, correct?
No, see here how to make sure that the view will have the underlying table changes by using sp_refreshview
Will the optimizer actually only pull view records that apply or will it pull all and then sub select the result set?
A view is nothing but a stored query, the optimizer is smart enough to do a range seek or scan on just the data it needs, you can verify this by looking at the execution plan
so I have a View with a total of 50 fields in it. If I selected only 2 fields from the view (one in each of two of the tables), would that query be slower than the equivalent table join script assuming you had all the same tables and joins?
again run stats io or time against the query with * and just 2 columns and look if you see a difference in reads and time
so for example
SET STATISTICS IO ON
GO
SELECT * FROM SomeView
SET STATISTICS IO OFF
GO
SET STATISTICS IO ON
GO
SELECT Col1, Col2 FROM SomeView
SET STATISTICS IO OFF
GO

Resources