Lining up Columns in SSRS report - ssrs-tablix

I have built a report and am having trouble lining up the columns from two tablix in the report.
I have created a report that looks at the counts of records in each table in the relivant database to make sure they have the correct amount of records in them, its a comparison between two databases and the tables held within them.
Dataset1 = new count of records
Dataset2 = old count of records
How can I get the two records sets too line up when one dataset contains more tables than the other data set:
Example of how it is now:
Dataset1 Dataset2
TableName RowCount TableName RowCount
------------------- -------------------
Table1 124 Table1 120
Table2 1 Table2 0
Table3 2658 Table4 5455
Table4 5455 Table6 50
Table5 54
Table6 54
Example of how it should be:
Dataset1 Dataset2
Tablix1 Tablix1
TableName RowCount TableName RowCount
------------------- -------------------
Table1 124 Table1 120
Table2 1 Table2 0
Table3 2658
Table4 5455 Table4 5455
Table5 54
Table6 54 Table6 50

Assuming that dataset1 always contains all of the table names you want:
Link the Tablix for Dataset2 to Dataset1
(Tablix Properties - Dataset Name)
Get the table names from Dataset1
(Enter Table names field in relevant textbox in tablix)
Use a lookup to get the rowcounts from dataset2
e.g.
=lookup(Fields!TableName.Value,Fields!TableName.Value,Fields!RowCount.Value,"Dataset2")
If you want the table name in dataset2 to be blank when no rows are returned, use an iif:
=IIF(isnothing(lookup(Fields!TableName.Value,Fields!TableName.Value,Fields!RowCount.Value,"Dataset2")),"",Fields!TableName.Value)

Related

Inserting selected data from table in one schema into another table in a different schema

I have a table A in Schema1 and table B in Schema2.
The tables have different columns.
Table A:
ID1 Name Code
-------------------------------
1 Skyler A0
2 Amanda A1
3 Rachel B0
4 Harvey C0
5 Louis B1
Table B:
ID Names Enterprise Modified_Date
------------------------------------------------------
1 Amanda 1 2018.08.10
2 Skyler 1 2018.08.11
As depicted, Schema1.A.Name = Schema2.B.Names
I want to insert the values "Rachel,Harvey and Louis" from A.Name into B.Names.
For b.ID, i have a sequence in place. Enterprise column is always 1 and modified date can e sysdate.
How can i achieve this in PL/SQL?
use insert Statement with select statement
insert into tabB (names,Enterprise,Modified_Date )
select Name,1,sysdate from tabA where Name in ('Rachel','Harvey','Louis');
You can do this by using below query.
insert into tableB (names,Enterprise,Modified_Date )
select Name,1,sysdate from tableA where Name not in (select distinct(Name) from tableB);

UPDATE Column data with the closest value from another table on oracle

I have this table "table_1"
Column
1039
3900
2345
And Table_2
Column
1038
1090
3903
4502
2340
2900
4500
i need to update the table_1 with the most closest value from table 2 to be like this :
1039 => 1038
3900 => 3903
and so on .
Thanks
Cross Join the tables, find the column in Table2 with the least difference.
Use the FIRST aggregate function to get this column.
SELECT a.col
,MIN(b.col) KEEP (
DENSE_RANK FIRST ORDER BY (ABS(a.col - b.col))
) as col2
FROM Table1 a
CROSS JOIN Table2 b
GROUP BY a.col;
Demo
To update the table, use a correlated update from the above select.
update table1 o set col = ( SELECT
MIN(b.col) KEEP (
DENSE_RANK FIRST ORDER BY (ABS(a.col - b.col))
) as col2
FROM Table1 a
CROSS JOIN Table2 b
Where a.col = o.col
GROUP BY a.col );

Oracle 20 million update based on join

I have a need to do the following
UPDATE TABLE2 t2
SET t2.product_id = (select t1.product_id from
table1 t1 where t1.matching_id = t2.matching_id)
Except that TABLE2 has 27 million records. The product_id is a newly added column and hence populating data to it.
I could use a cursor , break down my record set in TABLE2 to a reasonably smaller number, But with 27 million records, I am not sure whats the best way.
Pl suggest, even if it means exporting my data to excel.
Update - THe matching columns are indexed too.
The only thing I could do different is replace the update for a CREATE TABLE AS
CREATE TABLE table2_new AS
SELECT t2.* (less product_id), t1.product_id
FROM table1 t1
JOIN table2 t2
ON t1.matching_id = t2.matching_id
But later you will have to add the CONSTRAINTS manually, delete table2 and replace for table2_new
update (select t1.product_id as old_product_id, t2.product_id as new_product_id
from table1 t1
join table2 t2 on (t1.matching_id = t2.matching_id)) t
set t.new_product_id = t.old_product_id

Stored procedure to copy data from one table to multiple tables

Need help in writing a stored procedure, for copying data from one table to multiple tables.
Here is the scenario example:
Table1 has 10 columns with 20 rows of data.
Table2 (primary key will be sequence generator),Table3
Insert 4 columns values from Table1 into Table2, and 4 columns into Table3 (Check condition below)
Condition when inserting data into table3:
-Whenever data is inserted into Table3 (from table1) there will be one field in table3 which has the primary key value of Table2 and some values from Table 1.
Please help....
try INSERT INTO dest_table (COL1,COL2,...,COLn) SELECT COLa,COLb,...,COLz FROM source_table

How to update a table with null values with data from other table at one time?

I have 2 tables - A and B . Table A has two columns, pkey (primary key) and col1. Table B also has two columns, pr_key (primary key but not a foreign key) and column1. Both tables have 4 rows. Table B has no values in column1, while table A has column1 values for all 4 rows. So my data looks like this
Table A
pkey col1
A 10
B 20
C 30
D 40
Table B
pr_key column1
A null
B null
C null
D null
I want to update table B to set the column1 value of each row equal to the column1 value of the equivalent row from table A in a single DML statement.
Should be something like that (depends on SQL implementation you use, but in general, the following is rather standard. In particular should work in MS-SQL and in MySQL.
INSERT INTO tblB (pr_key, column1)
SELECT pkey, col1
FROM tblA
-- WHERE some condition (if you don't want 100% of A to be copied)
The question is a bit unclear as to the nature of tblB's pr_key, if for some reason this was a default/auto-incremented key for that table, it could just then be omitted from both the column list (in parenthesis) and in the SELECT that follows. In this fashion upon insertion of each new row, a new value would be generated.
Edit: It appears the OP actually wants to update table B with values from A.
The syntax for this should then be something like
UPDATE tblB
SET Column1 = A.Col1
FROM tblA AS A
JOIN tblB AS B ON B.pr_key = A.pkey
This may perform better:
MERGE INTO tableB
USING (select pkey, col1 from tableA) a
ON (tableB.pr_key = a.pkey)
WHEN MATCHED THEN UPDATE
SET tableB.column1 = a.col1;
It sounds like you want to do a correlated update. The syntax for that in Oracle is
UPDATE tableB b
SET column1 = (SELECT a.column1
FROM tableA a
WHERE a.pkey = b.pr_key)
WHERE EXISTS( SELECT 1
FROM tableA a
WHERE a.pkey = b.pr_key )
The WHERE EXISTS clause isn't necessary if tableA and tableB each have 4 rows and have the same set of keys in each. It is much safer to include that option, though, to avoid updating column1 values of tableB to NULL if there is no matching row in tableA.

Resources