SSRS data driven subscription email to : parameter dependent on report parameter? - sql-server

Hi I am using visual studio 2015 to make an SSRS 2014 report.
The place I am stuck at is my email recipient is dependent on what company is selected from the SSRS report.
Not that it should matter but my report parameters are Company
(really companyID),begdat,enddate.
select email from users where companyid= #companyid<< which would be my selection.
Most examples I see have a defined list of emails or just 1 person to email. I want to send a report per company only to the users of that company aka dynamic recipient list.

Modify your query as: select email, companyid from users
At the next step in select an option Get the value from the database for the TO field and set it to email.
At the next step change your company option to Get the value from the database and set it to companyid.
Then users from company CompanyA will receive only a CompanyA report, and CompanyB - only a CompanyB report.
You could debug the subscription using temporary query with only your email:
select email='your#email', companyid = 'CompanyAid'
UNION ALL
select email='your#email', companyid = 'CompanyBid'

Related

In SQL Server, how do I get the date of an event from a table and the date the previous event happened?

I'm using Microsoft SQL Server 2016 (SP2) (13.0.5026.0 (X64). I have a query that joins a people table with a contacts table. The people table has the client detail and the contacts table tells us the last time that client has made a contact.
The below query links the tables and gives me the client ID and the date they made contact
SELECT
DP.dim_person_ID AS [Dim_Person_ID],
CAST(FC.CONTACT_DTTM AS date) AS [Contact Date]
FROM
Child_Social.Fact_Contacts FC
INNER JOIN
CHILD_SOCIAL.DIM_Person DP ON FC.dim_person_ID = DP.Dim_Person_ID
If they made multiple contacts they will return a row for each one and the output will look like this
Person_ID
Contact Date
1
01/01/2023
1
01/10/2022
1
01/07/2022
1
01/04/2022
1
01/01/2022
2
02/01/2023
2
02/10/2022
2
02/07/2022
2
02/04/2022
2
02/01/2022
What I'm trying to do is to add a column to the query that shows the previous contact date as well eg return an output like
Person ID
Contact Date
Previous Contact Date
1
01/10/2022
01/07/2022
1
01/07/2022
01/04/2022
2
02/10/2022
02/07/2022
2
02/07/2022
02/04/2022
I'm unsure how to create a join/sub query that will calculate a previous episode (rather than a most recent episode or a first episode, just the previous one).
Any help or guidance gratefully received

SQL Server view for PII and Non PII end user

I have situation where I need to create a view which will be used by end user who may have PII and NON-PII permission clearance controlled by AD groups.
Say i have dim_customer which contains four columns ID, Name, DoB, Country. When PII user runs
Select ID, Name, DoB, Country FROM dim_customer
the pii user should get
ID NAME DoB Country
1 John 1999-10-10 US
If the same query is run by NON-PII user then they should get
ID NAME DoB Country
1 PII DATA PII DATA US
So basically same view object is used but data is displayed according to the pii clearance.
I dont want to create two views with pii and non-pii suffix.
I tried column level permission but that means when end user try the above
query they get error "no select permission on Name and DoB Columns"
I have tried Data Masking but that shows "XXXX" and i would prefer "PII
Data".
I am looking for a solution where the query runs successfully and show results as above.
Is this possible in SQL Server ?
thanks in advance
Create two roles, one that allows PII data, and one that doesn't. Put each user into one role or the other. Than write your view
Select
ID,
Name,
CASE
WHEN IS_ROLEMEMBER ('pii_role') = 1 THEN DoB
ELSE 'PII Data'
END as DoB,
Country
FROM dim_customer

Crystal Reports - massive change table name or edit SQL Server query at runtime

I have 170+ reports and our customer would like to decrypt some of data.
For example: report returns first/last name with address, Personal Identification Number etc.
What I need to do is somehow massively change all reports table name, from Contact to Contact_R (which already include encrypted data) OR maybe there is any way to create something like trigger but in SQL Server, so I could edit query (with replace table name) before it will be executed, fe.
SELECT firstName, lastName FROM Contact
becomes
SELECT firstName, lastName FROM Contact_R

SSRS load report even if cascading parameter is empty

I have cascading parameters like: Year > Company After choosing Year value, Company parameters are refreshed.
So for example If I choose 2016, but at this year no data, Company parameter is empty (no values) and report says that parameter can't be blank (I've checked "Allow blank values """, but It not working with multivalued parameters) See image below:
How can I load report with message like: "Sorry, there is no data"? Or provide any default value for Company parameter if there is no other values? Have you any ideas?
One solution is to make your Year parameter data-driven, from the same table as your companies. Make a new dataset like the one below, and use it as the available values for your Year parameter.
SELECT DISTINCT year
FROM companies
WHERE report_relevant = 'Yes'
ORDER BY 1
This limits the users to only pick years where valid companies exist. As soon as a 2016 company is added to your data, the report will automatically include 2016 as a Year parameter option.
You could use a UNION to add an extra row of data to your parameter, but Count() your valid companies so the extra row is only included when no other companies would be.
SELECT company_id, company_name
FROM companies
WHERE year = #Year
UNION
SELECT '-1', 'No companies in ' + #Year
WHERE (SELECT Count(company_id) FROM companies WHERE YEAR = #Year) = 0

Data synchronization web

Data synchronization on multiple locations:
Application is deployed on different locations, I want to update master database at the end of day such that new sales orders of the day from all locations
should be inserted into master database.
At the time of insertion of a new sales order in the local database at a particular location,
application first ensure that this customer is new customer who is not in the local as well as master database.
If customer data is already present in the master database , then local database must be populated with essential details of a customer available in the master
daabase.
Customer:
CUST_ID sequence (PK)
Name varchar2
DOB DateTime
SSN DateTime
Customer_Detail:
CUST_ID (FK) Refrences Customer,
PhoneNumber
email
Customer_Order:
Order_ID
CUST_ID
Order_Date
Order_Detail:
Order_ID
Product_Id
Quantity
At the end of day I want to update the master database, with all the details of new data that is inserted in the databases on different locations.
The approach which i want to follow is:
searchMasterDatatabse(ssn)
{
//select name, dob,ssn from customer where ssn=:ssn
if(recordFound)
set recordExistInMasterDatabase=true;
}
if (recordExistInMasterDatabase)
{
insert into location.Cutomer(name,dob,ssn) values(master.name,master,dob,master.ssn)
}
else
{
insert into location.Cutomer(name,dob,ssn) values('John','19-MAR-2012','1111-222222-8989888'}
}
Now at the end of day i want to update the master database with the new customers that are registered on different locations.
Please suggest me the articles, techniques, tutorial so that i can achive the above functionality. I want to start my work after deciding a particular technique.
Is there any tool to do this?
What about oracle data integrator?
Should I implement web service to communicate with the master database?
I want to implement this using pure java + oracle sql + jsf for web.
I have eclipse, oracle 11g.

Resources