Control Page Break in SSRS - ssrs-2012

I have a table which contain hundred of columns for the table and I would like to create multi pages to display each single record in SSRS.
Can you advise how to add page break . I have search all of solution and also find the union SQL , it seem doesn't help, I give the below example and expect output for your reference
Report Table structure as below
Column1
Column2
Column3
.
Column99
I want the report layout is
Record : 1
Column1 : Column1.Value
Column2 : Column2.Value
Column3 : Column3.Value
Column4 : Column4.Value
----- page break -----
Record : 1
Column4 : Column4.Value
Column5 : Column5.Value
Column6 : Column6.Value
Column7 : Column7.Value
----- page break -----
Record : 1
Column85 : Column85.Value
Column89 : Column89.Value
----- page break -----
Record : 2
Column1 : Column1.Value
Column2 : Column2.Value
Column3 : Column3.Value
Column4 : Column4.Value
----- page break -----
Record : 2
Column4 : Column4.Value
Column5 : Column5.Value
Column6 : Column6.Value
Column7 : Column7.Value
----- page break -----
Record : 2
Column85 : Column85.Value
Column89 : Column89.Value
Thank you

Related

Filtering columns only "if" certain condition is satisfied

I am having table as below
And I want output as below
I tried doing something as below
SELECT * FROM TABLE_NAME WHERE COLUMN2 = 'PQR' AND COLUMN3 IS NOT NULL
But it also removes 3rd and 4th row from 1st table. Whereas in output of the query I need to remove only rows which are having Column2 as PQR and Column3 as NOT NULL
I also tried to use case statements but I'm not able to get actual idea of how to implement it.
EDIT 1:-
Also I thought of trying one more thing now.
SELECT * FROM TABLE_NAME WHERE COLUMN2 IN ('PQR', 'XYZ', 'RST') AND COLUMN3 IS NOT NULL
But the problem is in actual table COLUMN2 is having more than 150 distinct values which I can't go on mentioning in IN clause.
not(COLUMN2 = 'PQR' AND COLUMN3 IS NOT NULL)
Example:
SQL> ;
1 with -- test data:
2 t(column1,column2,column3) as (
3 select 'ABC','PQR',cast(null as int) from dual union all
4 select 'DEF','PQR',123 from dual union all
5 select 'GHI','XYZ',cast(null as int) from dual union all
6 select 'JKL','RST',cast(null as int) from dual
7 ) -- test query:
8 select *
9 from t
10* where not(COLUMN2 = 'PQR' AND COLUMN3 IS NOT NULL)
SQL> /
COL COL COLUMN3
--- --- ----------
ABC PQR NULL
GHI XYZ NULL
JKL RST NULL
or lnnvl(COLUMN2 = 'PQR') or COLUMN3 IS NULL
Example:
with -- test data:
t(column1,column2,column3) as (
select 'ABC','PQR',cast(null as int) from dual union all
select 'DEF','PQR',123 from dual union all
select 'GHI','XYZ',cast(null as int) from dual union all
select 'JKL','RST',cast(null as int) from dual
) -- test query:
select *
from t
where lnnvl(COLUMN2 = 'PQR') or COLUMN3 IS NULL;
COL COL COLUMN3
--- --- ----------
ABC PQR NULL
GHI XYZ NULL
JKL RST NULL
What you want is (if I understood correctly)
NOT (COLUMN2 = 'PQR' AND COLUMN3 IS NOT NULL)
which is equivalent to
COLUMN2!='PQR' OR COLUMN3 IS NULL

Check for != values when column contains records with NULLs

I have a number of tables that mix 'real' values with nulls in columns. From exerience, issuing a SELECT against these that looks like:
SELECT column1, column2, column3 FROM mytable WHERE column1 != 'a value';
...doesn't return the records I expect. In the current table I am working on, this returns an empty recordset, even though I know I have records in the table with NULLs in column1, and other records in the table that have the value I am "!="ing in column1. I am expecting, in this case, to see the records with NULLs in column1 (and, of course, anything else if there were other not 'a value' values in column1.
Experimenting with NVL in the WHERE clause doesn't seem to give me anything different:
SELECT column1, column2, column3 FROM mytable WHERE NVL(column1, '') != 'a value';
...is also returning an empty recordset.
Using 'IS NULL' will technically give me the correct recordset in my current example, but of course if any records change to something like 'another value' in column1, then IS NULL will exclude those.
NULL can't be compared in the same way that other values can be. You must use IS NULL. If you want to include NULL values, add an OR to the WHERE clause:
SELECT column1, column2, column3 FROM mytable WHERE column1 != 'a value' OR column1 IS NULL
The query doesn't work because SQL handles equality checks (!=) different from checking if null (IS NULL).
What you could do here is something like:
SELECT column1, column2, column3
FROM mytable
WHERE column1 != 'a value' OR column1 is null;
See Not equal <> != operator on NULL.
What you were trying was correct. You just need change it a little. see below-
SELECT column1, column2, column3 FROM mytable WHERE NVL(column1, '0') != 'a value';
Instead of empty string, pass any character in NVL's second argument.
"Experimenting with NVL in the WHERE clause doesn't seem to give me anything different"
That's true:
SQL> select * from mytable;
COLUMN1 COLUMN2 COLUMN3
-------------------- ---------- ---------
a value 1 25-JUL-17
not a value 2 25-JUL-17
whatever 3 25-JUL-17
4 26-JUL-17
SQL> SELECT column1, column2, column3 FROM mytable WHERE NVL(column1, '') != 'a value';
COLUMN1 COLUMN2 COLUMN3
-------------------- ---------- ---------
not a value 2 25-JUL-17
whatever 3 25-JUL-17
SQL>
This is because your experiment didn't go far enough. For historical reasons Oracle treats an empty string as null so your nvl() statement effectively just subs one null for another. But if you had used a proper value in your call you would have got the result you wanted:
SQL> SELECT column1, column2, column3 FROM mytable WHERE NVL(column1, 'meh') != 'a value';
COLUMN1 COLUMN2 COLUMN3
-------------------- ---------- ---------
not a value 2 25-JUL-17
whatever 3 25-JUL-17
4 26-JUL-17
SQL>
The alternative approach is to explicitly test for NULL and test for the excluding value...
SQL> SELECT column1, column2, column3 FROM mytable
2 where column1 is null or column1 != 'a value';
COLUMN1 COLUMN2 COLUMN3
-------------------- ---------- ---------
not a value 2 25-JUL-17
whatever 3 25-JUL-17
4 26-JUL-17
SQL>
The second approach is probably more orthodox.
1) Undocumented Oracle function SYS_OP_MAP_NONNULL. (It exists from oracle10)
with abc as ( select 'a value' as col1 from dual
union all
select '' as col1 from dual)
select * from abc
where SYS_OP_MAP_NONNULL(col1) != SYS_OP_MAP_NONNULL('a value')
;
2) LNNVL - Check table in the documentation for clarification.
with abc as ( select 'a value' as col1 from dual
union all
select '' as col1 from dual)
select * from abc
where lnnvl( col1 = 'a value');
;

change the value of a query when inserting

tab1
column1 =4
column2 = (empty column )
column3 = also empty
what I want is when I insert data into column2
column2 = test
I want column 2 to have the data of column1 , I want to have such result
column 2= 4test
I know I can achieve that with a trigger or procedure , I am asking you if there is another way when I insert it
Try
update tab1 set column2 = column1 || 'test' where condition;

How to use if clauses on queries in iReport

I have the following query:
SELECT COLUMN1, COLUMN2, COUNT(*)
FROM TABLE
WHERE COLUMN3 IS NOT NULL
AND COLUMN4 = 1
AND COLUMN5 = 4
AND COLUMN6 = 43
AND COLUMN7 = $P{YEAR}
AND COLUMN8 = $P{IT}
GROUP BY COLUMN1, COLUMN2
ORDER BY COLUMN1 ASC
I wonder if it is possible to do something like:
SELECT COLUMN1, COLUMN2, COUNT(*)
FROM TABLE
WHERE COLUMN3 IS NOT NULL
AND COLUMN4 = 1
AND COLUMN5 = 4
AND COLUMN6 = 43
AND COLUMN7 = $P{YEAR}
IF ($P{IT} != 'ALL') { AND COLUMN8 = $P{IT} }
GROUP BY COLUMN1, COLUMN2
ORDER BY COLUMN1 ASC
In other words, I want to add to the where clause "AND COLUMN8 = $P{IT}" only if "$P{IT}" value is not "ALL". This means if the report must filter by the column "COLUMN8" or not.
Do someone know if this is possible? Is there other approach that accomplish the work?
I tried to execute the above query but I got a 'Compilation running time'.
Thanks in advance.
Yes, you can do that in iReport. But you need to look at it slightly differently. You need a second parameter. Keep $P{IT}, and add $P{IT_SQL}. Give $P{IT_SQL} a default value like this:
$P{IT}.equals("ALL") ? "" : " AND COLUMN8 = '" + $P{IT} + "'"
Then your query should look like this:
SELECT COLUMN1, COLUMN2, COUNT(*)
FROM TABLE
WHERE COLUMN3 IS NOT NULL
AND COLUMN4 = 1
AND COLUMN5 = 4
AND COLUMN6 = 43
AND COLUMN7 = $P{YEAR}
$P!{IT_SQL}
GROUP BY COLUMN1, COLUMN2
ORDER BY COLUMN1 ASC
That will give you the desired SQL (none!) when $P{IT} has the value "ALL", and it will give you the desired SQL (COLUMN8 = 'abc') when $P{IT} has the value "abc".

to Create a bat file to run a query

I need to create a bat file which include a query to run a package.
I use plsql developer to develop the package. its username,password and database is user,pswd,db1 respectively.
The query to run the package is:
SELECT
COLUMN1 AS "LAST NAME",
COLUMN2 AS "FIRST NAME",
COLUMN3 AS "LOCATION"
FROM TABLE(PKG.GET_SUM('09-NOV-2010','12-NOV-2010'))
can anyone help me what code shud I write to create a bat file
Thanks in advance
This is my code
connect usr/pswd#db1
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 100
COLUMN COLUMN1 HEADING 'LAST NAME'
COLUMN COLUMN2 HEADING 'FIRST NAME'
COLUMN COLUMN3 HEADING 'LOCATION'
spool c:\temp\get_sums.csv
SELECT COLUMN1
,COLUMN2
,COLUMN3
,COLUMN4
,COLUMN5
, COLUMN6
,COLUMN7,
COLUMN8
,COLUMN9
FROM TABLE(ACTY_SUMM('09-NOV-2010','12-NOV-2010'))
/
spool off
exit;
I changed the line size and pagesize. But not able to get the desirable format. I have 12 columns. I need it in a report format.
Hi I tried to change the Linesize,but still I am not getting the desired format. I want the report in the following format
FirstNAME LASTNAME LOCATION A B C D E F G H I
NAME1 LNAME1 LOC1 A1 B1 C1 D1 E1 F1 G1 H1 I1
NAME2 LNAME2 LOC1 A2 B2 C2 D2 E2 F2 G2 H2 I2
LOCTOT
NAME3 LNAME3 LOC2 A3 B3 C3 D3 E3 F3 G3 H3 I3
LOCTOT
I need all the column in one row and their corresponding values of each person under each column and after each location there will be location total and at the end there will be grant total. I tried with the linesize,page size and all. still no result. Can anyone help me to get the report in this format
Hi
As of now client is ok with the csv format. But the challenge is I am not getting the heading. This is my code in sql script.
connect usr/pwd#db1
SET NEWPAGE 0
SET LINESIZE 100
SET PAGESIZE 0
spool c:\temp\q1.csv
COLUMN COLUMN1 HEADING 'LAST NAME'
COLUMN COLUMN2 HEADING 'FIRST NAME'
COLUMN COLUMN3 HEADING 'LOCATION'
COLUMN COLUMN4 HEADING 'A'
COLUMN COLUMN5 HEADING 'B'
COLUMN COLUMN6 HEADING 'C'
COLUMN COLUMN7 HEADING 'D'
COLUMN COLUMN8 HEADING 'E'
COLUMN COLUMN9 HEADING 'F'
COLUMN COLUMN10 HEADING 'G'
COLUMN COLUMN11 HEADING 'H'
COLUMN COLUMN12 HEADING 'I'
SELECT
'"'||COLUMN1
||'","'|| COLUMN2
||'","'|| COLUMN3
||'","'|| COLUMN4
||'","'|| COLUMN5
||'","'|| COLUMN6
||'","'|| COLUMN7
||'","'|| COLUMN8
||'","'|| COLUMN9
||'","'|| COLUMN10
||'","'|| COLUMN11
||'","'|| COLUMN12||'"'
FROM
TABLE(ACTY_SUM('09-NOV-2010','12-NOV-2010'))
/
spool off
exit;
Can you please suggest on this issue
First create a script to run the query. You'll want to capture the output to a file, hence the SPOOL command.
connect usr/pswd#db1
spool c:\temp`get_sums.lst
SELECT
COLUMN1 AS "LAST NAME",
COLUMN2 AS "FIRST NAME",
COLUMN3 AS "LOCATION"
FROM TABLE(PKG.GET_SUM('09-NOV-2010','12-NOV-2010'))
/
spool off
exit;
save that to a file called get_sums.sql . Then you need a batch file get_sums.bat like this:
sqlplus /nolog #C:\get_sums.sql
There are various SQL*Plus commands you can include in the .sql file t format the output. Find out more.
Apparently a link to the formatting documentation is not sufficient.
There is no point in setting LINESiZE to 80, that is the default. If you are selecting nine columns and you want all nine values to appear on one line you need to set the LINESIZE so that it is long enough to accomodate all the columns. This means you need to set LINESIZE to the sum of all the columns' widths plus eight (the number of interstitial spaces between ninbe columns).
Although I see you have tried
SET SPACE 0
This causes all the selected columns to run together in one long line, which is a highly unusual way of laying out a report. But if that's really what you want then ignore the interstitial spaces when calculating the correct value for LINESIZE.
Having formatted you posted code I see you are outputting to .csv. Why didn't you say you wanted to export comma separated values in the first place?
There are several ways of doing this. The most straightforward is to concatenate your query's projection with commas:
SELECT
'"'||COLUMN1
||'","'|| COLUMN2
||'","'|| COLUMN3
||'","'|| COLUMN4
||'","'|| COLUMN5
||'","'|| COLUMN6
||'","'|| COLUMN7
||'","'|| COLUMN8
||'","'|| COLUMN9 ||'"'
FROM TABLE(ACTY_SUMM('09-NOV-2010','12-NOV-2010'))
/
The double-quotes are the optional field terminators, which will handle any string columns which contain commas.
"I dont want coma seperated values. I
edited my post. Please suggest "
Here is some test data:
SQL> select * from t23
2 /
♀FIRSTNAME LASTNAME LOCATION A B C D E F
-------------------- -------------------- ---------- -- -- -- -- -- --
G H I
-- -- --
NAME1 LNAME1 LOC1 A1 B1 C1 D1 E1 F1
G1 H1 I1
NAME2 LNAME2 LOC1 A2 B2 C2 D2 E2 F2
G2 H2 I2
NAME3 LNAME3 LOC2 A3 B3 C3 D3 E3 F3
G3 H3 I3
SQL>
I can produce the basic layout you want using SQL*Plus formatting commands
SQL> set linesize 100
SQL> break on location
SQL> compute count of location on location
SQL> compute count of location on report
SQL> r
1* select * from t23
♀FIRSTNAME LASTNAME LOCATION A B C D E F G H I
-------------------- -------------------- ---------- -- -- -- -- -- -- -- -- --
NAME1 LNAME1 LOC1 A1 B1 C1 D1 E1 F1 G1 H1 I1
NAME2 LNAME2 A2 B2 C2 D2 E2 F2 G2 H2 I2
----------
2
NAME3 LNAME3 LOC2 A3 B3 C3 D3 E3 F3 G3 H3 I3
----------
1
SQL>

Resources