ALL parameter for SSRS Report - visual-studio

I want to be able to let the business manually enter a USERID into a parameter box or leave it blank for it to bring back all USERID's.
I have setup another parameter for CUSTOMERID which uses a dataset to bring back a list of customer ID's. Due to the amount of USERID's I don't want to use the same solution but instead have them manually enter the USERID or leave it blank and bring back ALL.
SELECT
CUSTOMERID,
CASE
WHEN STATUSCODE = 200 THEN 'Successful Logon'
ELSE 'Unsuccessful Logon'
END as LogonStatus,
COUNT( * ) COUNTOFACCOUNTS
FROM
MA4EQNG.APPLICATIONLOG
WHERE
CUSTOMERID in ('"+join(Parameters!CustomerID.Value, "','")+"')
AND (Cast(DATETIME as Date) >= '"& Format(Parameters!FromDate.Value, "yyyy-MM-dd") & "'
AND Cast(DATETIME as Date) <= '" & Format(Parameters!ToDate.Value, "yyyy-MM-dd") & "')
AND COMPONENTDESCRIPTION = '/eq/auth/v1/logon'
AND METHOD = 'POST'
GROUP BY
CUSTOMERID,
CASE
WHEN STATUSCODE = 200 THEN 'Successful Logon'
ELSE 'Unsuccessful Logon'
END
ORDER BY
CUSTOMERID ASC
Please let me know if you need anything else.

You can set the USERID parameter to allow blank value then use IF condition on your main dataset sql script.
Try
IF LEN(#USERID)>0
*put the sql script with UserId filter in where clause*
ELSE
*put the sql script WITHOUT UserId filter in where clause*

Normally you would just script something like this in the WHERE clause.
WHERE
isnull(#CustomerID,'') = '' OR (CUSTOMERID in('"+join(Parameters!CustomerID.Value, "','")+"'))
And long term, I would create a function that takes in a delimited string, and converts them to rows, then you can just join on the results from the table valued function.
How to split a comma-separated value to columns

Related

LINQ Query can return the counts of each column of DataTable

I have a query, I am using a data table and I want to see each variable how many rows have values without null and value(-1) in that particular column. If anyone can help me to use the LINQ query and check the numbers.
Example: I have a table (City, Age, Gender) and i want to show the user that which column has blanks.... I mean in my current dataset city & Age has 200 rows but gender has 170 due to punching error so I through the loop to check each column I want to show the counts.
Here is what I have tried but that is not working. And its Vb.net code.
Dim dtRaw As New DataTable
daGlobal = New OleDb.OleDbDataAdapter(CMD, MyConnection)
daGlobal.Fill(dtRaw)
daGlobal.Fill(dtGlobal)
For Each column As DataColumn In dtRaw.Columns
Dim xss As String = column.ColumnName
Dim MyCounts = (From xss In dtRaw.AsEnumerable()
Where (Not String.IsNullOrEmpty(xss)).Count())
Next

Compare two records and highlight the differences

I have a oracle apex report which fetches two rows every time.
I want to highlight all the columns where data is different in two rows.
So when user looks at the comparison report he don't have to go through all the columns to identify where data has been changed.
I have tried to look at the apex features and some javascript code but was unable to do so reliably.
You can have a look at sample report here:
https://apex.oracle.com/pls/apex/f?p=128616:8:109311280077805:::::
go to page "help me with comparison"
I want to highlight the benefit name column as data is different in benefit name column.
if your table has id "test" you can try call this function on page load compareRows(document.getElementById('test'));
the function body:
function compareRows(table) {
var row1,row2, rows = table.rows;
var cell1,cell2;
var rowText;
row1=rows[1];
row2=rows[2];
cell1=row1.cells;
cell2=row2.cells;
for (var i=0; i<cell1.length; i++) {
if(cell1[i].textContent != cell2[i].textContent){
cell1[i].style.backgroundColor = "red";
cell2[i].style.backgroundColor = "red";
}
}
}
You can use the analytic function "LAG" to reference the previous row in your resultset.
So one possible solution is to (1) select the value of the current row and the value of the previous row, (2) compare the 2 columns and set a flag, only in row 2 because that is where you want to highlight, (3) use highlighting in apex to indicate which columns have different values. See example sql below for an example.
-- create tables
create table so_dummy_data (
id number generated by default on null as identity
constraint so_dummy_data_id_pk primary key,
name varchar2(100) not null,
email varchar2(100) not null
)
;
-- load data
insert into so_dummy_data (
id,
name,
email
) values (
1,
'John Doe',
'john.doe#mail.com'
);
insert into so_dummy_data (
id,
name,
email
) values (
2,
'John Doe',
'john.x.doe#mail.com'
);
commit;
WITH old_and_new AS
(SELECT
id,
name,
LAG(name,1)OVER(
ORDER BY
name
)AS new_name,
email,
LAG(email,1)OVER(
ORDER BY
1
)AS new_email,
row_number() over (order by 1) rn
FROM
so_dummy_data
)
SELECT
name,
CASE
WHEN rn = 1 THEN 'N'
WHEN name = new_name THEN
'N'
ELSE
'Y'
END AS name_changed,
email,
CASE
WHEN rn = 1 THEN 'N'
WHEN email = new_email THEN
'N'
ELSE
'Y'
END AS email_changed
FROM
old_and_new;

oracle - UPDATE SQL: how to update several times the same line

I need to Update quantity of several books, before delete them.
the deleting happen with this code (oracle has a hidden column called ROWNUM)
DELETE FROM project.cart WHERE isbn = ? and ROWNUM=1;
to delete ISBN one at time (there are equal isbn in the table). but the update only works for one isbn. it should update several times the same line for all isbn found.
String sql3= "UPDATE PROject.book SET quantity=quantity +1 WHERE project.book.isbn in "
+ "(SELECT project.cart.isbn FROM project.cart) ";
// this code work perfectly, but for one time.
I hope you can help me. thanks
You can try this:
String sql3= "UPDATE PROject.book SET quantity=quantity + "
+ "(select count(*) FROM project.cart where project.cart.isbn = project.book.isbn) "
+ " WHERE project.book.isbn in (SELECT project.cart.isbn FROM project.cart)";
Do you mean that if a book is in the cart three times it should have 3 added its quantity column?
If so, you need to add the count. When a row is included by the WHERE logic, it's included only once, even if it matched more than one of the criteria. Try a correlated subquery instead:
UPDATE book
SET quantity = quantity + (SELECT COUNT(*) FROM cart WHERE book.isbn = cart.isbn)
This query will run very slowly if there are a lot of book rows, so you may want to add your original WHERE clause to the end to limit the number of book rows:
UPDATE book
SET quantity = quantity + (SELECT COUNT(*) FROM cart WHERE book.isbn = cart.isbn)
WHERE isbn IN (SELECT isbn FROM cart)

Using group by subquery to deduplicate record set

I would like to know how I can return the activity Id to a parent query using a query like the following to de-duplicate the parent record set. The issue here is that using this group by or distinct I cannot find a way.
I will use all of the group by fields to determine a unique record. But, I need to use only the record with the select min(status.effective_date)
The query returns the correct date values, but I cannot link it back to the parents activity records with just that date value.
select min(status.effective_date)
from accounts
, address
, activity
, status
where accounts.par_row_id = activity.account_id
and address.row_id = activity.address_id
and status.par_row_id = activity.status_id
and account.name = 'xyz'
group by account.name, address.addr, address.ADDR_LINE_2, address.ADDR_LINE_3
, address.ADDR_LINE_4, address.CITY, address.COUNTRY, address.X_STATE
, address.ZIPCODE
You should try this query:
select min(activity.row_id) keep(dense_rank first order by status.effective_date) as activity_id
from accounts
, address
, activity
, status
where accounts.par_row_id = activity.account_id
and address.row_id = activity.address_id
and status.par_row_id = activity.status_id
and accounts.name = 'xyz'
group by accounts.name, address.addr, address.ADDR_LINE_2, address.ADDR_LINE_3
, address.addr_line_4, address.city, address.country, address.x_state
, address.ZIPCODE;

Change DataSet Designer parameter inference

I'm using the VS2010 DataSet designer to make some select queries with optional parameters similar to this:
SELECT CustomerID, FirstName, JoinDate, etc
FROM tblCustomers
WHERE (
(#CustomerID IS NULL OR CustomerID = #CustomerID) AND
(#FirstName IS NULL OR FirstName = #FirstName) AND
(#JoinedBefore IS NULL OR JoinDate < #JoinedBefore) AND
(#JoinedAfter IS NULL OR JoinDate > #JoinedAfter) AND
.. etc ..
)
The inference for these properties data-types and allow DB null is almost always wrong. I end up with string types set for date time and vice versa. Over half the fields are always marked as non-null.
That obviously wreaks havoc on my queries. I can manually change these inference's, but every time I have to update the TableAdapter, it resets them all to what it thinks is best! Anyone know how to either a) get the inferences right, or b) override them in a permanent way?
It seems VS infers the data type based on the first occurrence of the parameter in the query. Because I put my #Parater IS NULL OR... first, that confused the designer and caused it to infer wrong a lot of the time. I swapped the order of my query and now it infers perfectly:
SELECT CustomerID, FirstName, JoinDate, etc
FROM tblCustomers
WHERE (
(CustomerID = #CustomerID OR #CustomerID IS NULL AND
(FirstName = #FirstName OR #FirstName IS NULL) AND
(JoinDate < #JoinedBefore OR #JoinedBefore IS NULL) AND
(JoinDate > #JoinedAfter OR #JoinedAfter IS NULL) AND
.. etc ..
)

Resources