SSRS pass through Delivery Options - sql-server

Just curious, I was attempting to create an SSRS subscription and in the data driven query have it set to if the view returns any rows above 0 then send out the emails based on the delivery options.
At first I came up with this;
if (select count(*) from view.table) > 0
print ('Data Available')
And it works! but it sends multiple emails based on the number of rows it returns back which isn't good. Also if no rows are returned, it doesn't send, which is also good but it flags as an error in SSRS. My requirements are that if any row is returned back, send out the report via email to the specified email addresses. If no rows are returned from that view, then don't send at all.
I came up with this next query but I am unsure of the syntax.
if (select count(*) from view.table) > 3
select email:To
I know this SQL above won't work but I can't figure out the syntax.
Essentially, I want to see if it's possible to use the delivery options from the page prior in SSRS of the Data Driven query Page. If not, would I have to create another view or table that has that email info? Is there a better way of going about this?
Thank you for your help!

Related

How to send an email from a query result having more than one line

I'm trying to send emails via a sql query that contains multiple lines. What is the best way to combine them into a batch or a group so that it doesn't send me hundreds of emails?
So for example the query returns 100 rows and the last two columns are person name and email. They are of course duplicated all the way down from 1-100. So I would like to send those 100 rows to said person via their email address.
I have tested on a single line for different people, seem to work perfectly, although the problem occurs when there is multiple lines for each person (grouped by diff email address).
This is pretty straight forward in SSRS, but at the moment that is not an option.
We have a table with duplicates and unique records.
Created logic app as shown below:
In Execute query action, written sql query as:
SELECT Name,Email, COUNT (*) FROM [dbo].[Persons] GROUP BY Name,Email HAVING COUNT(*) > 1;
This will fetch duplicate records from table.
In send email action, given 'To' address from the execute query result action as shown below:
body('Execute_a_SQL_query_(V2)')?['resultsets']?['Table1'][0]?['Email']
Output Email:

Service Availability Checking

This is going to be a lengthy question.
First of all what I need to get done is to display available services(service will be either room1,room2,pool1,pool2 etc.) for a given period.
I have three tables which could be related to this query.
1. Service Type Table : Room,Pool etc.
2. Service Table: R1,R2,P1,P2 etc.
3. Items Reserved Table : This table holds a record for each service consumed by a given reservation ID.
Following is the snap of db diagram.
The system user will input Res_ID,Cust_ID,Date_In,Date_Out and select the service type from combo box. Then I have following View1 to get available service Ids
(SELECT dbo.Items_Reserved.Service_ID
FROM dbo.Items_Reserved INNER JOIN
dbo.Reservation ON dbo.Items_Reserved.Res_ID = dbo.Reservation.Res_ID
WHERE (dbo.Items_Reserved.Date_In > '$date_in') AND (dbo.Items_Reserved.Date_Out < '$date_out'))
First of all I want to know whether this is correct. I can not check whether this is correct as I dont know how to execute this view in my codes.
I use sql server and vb.net
Please help. I searched every where and could not find an answer.

SQL Report Service Subscription with dynamic report paramater's values

Background
I have a report with 3 parameters: AccountId, FromDate and ToDate. The report is invoice layout. Customer want to view all members which means we have 300 members, system will generates 300 reports in pdf or excel format and send to customer.
Question
How to set member id for this in subscription? I cannot do one by one and create 300 subscriptions in manually :|
If you're not clear, please comment below and I will correct it asap.
Updated:
The data-driven subscription which Manoj deal with is required SQL Report has Enterprise or Developer editon.
If I don't have, do you have any solution for work around?
If you are stuck with the Standard edition of SQL Server, you'll need to create a SSIS package to generate the reports. I used the article below to set up a package that now creates and emails our invoices, order confirmations, and shipping acknowledgments. I like this article over other ones I found because it's so easy to add more reports to it as you go along without having to create a new package each time.
If you plan to use this for more than one report, I would change the parameter to be a PK so that you know you're always going to pass in one integer regardless of which report you're calling. Another change I made was to create one table for the report generation piece, and one for the email piece. In my case, I only want to send one email that may have multiple attachments, so that was the best way to do it. In your stored proc that builds this data, make sure you have some checks for if the email is valid.
update TABLE
set SendStatus = 'Invalid Email Address'
where email NOT LIKE '%_#__%.__%' --valid email format
or patindex ('%[ &'',":;!=\/()<>]%', email) > 0 -- Invalid characters
or patindex ('[#.-_]%', email) > 0 -- Valid but cannot be starting character
or patindex ('%[#.-_]', email) > 0 -- Valid but cannot be ending character
or email not like '%#%.%' -- Must contain at least one # and one .
or email like '%..%' -- Cannot have two periods in a row
or email like '%#%#%' -- Cannot have two # anywhere
or email like '%.#%' or email like '%#.%' -- Cant have # and . next to each other
--0
When I set this up, I had a lot of issues getting the default credentials to work. The SSRS services would crash every time, but the rest of the SQL services would keep working. I ended up having our network guy make a new set with a static password just for this. If you do that, change the default credential line to this one.
rs.Credentials = new System.Net.NetworkCredential("acct", "p#ssword", "domain");
If you run into errors or issues, the SSRS logs and Google are your best friends. Or leave a comment below and I'll help.
Here's that article: http://technet.microsoft.com/en-us/library/ff793463(v=sql.105).aspx
use this link for reference:
http://beyondrelational.com/modules/2/blogs/101/posts/13460/ssrs-60-steps-to-implement-a-data-driven-subscription.aspx
create your SQL statement like this:
This will solve your problem.

WCF Connection very slow - Is the WPF Client the issue or the SQL Query?

I have a SQL Server database with table containing 300.000 data rows. There is an Index on the Primary Key and another key. I am using the following query in my standalone WCF server to fetch the data using an SQLConnection and SQLDataReader.
SELECT * FROM Users WHERE UserTypeId = #UserTypeId ORDER BY Users.Id OFFSET
#OFFSET ROWS FETCH NEXT #NUMBER ROWS ONLY
The Data returned by the DataReader is pushed into my own Class/Model and than returned by the function of the WCF server.
The WPF Client connects to the server and starts the command and only wants 500 data rows. However the time needed for this task is about 3-4 seconds. (Not mentioning the time for all data...)
The returned List is then used as the DataContext for the WPF Datagrid.
My question is, what can I check or what might be wrong. If you need more Information,CodeSamples,etc. please let me know!
First, don't use select *, instead specify what fields you want from the table. Now you are getting data that you don't need, for example the UserTypeId field which you already know for all the records that you get.
Then you can create a covering index that contains UserTypeId and Id, and has any other fields that you want to return from the query as included fields. That way the database can run the query against the index alone, and doesn't have to read anything from the actual table.

Best practices for displaying reports

I currently have a client-server application. The client needs to be able to generate reports. These reports can have millions of records. What is the best way to get the data to the client? Sending all million records at once is not very efficient. Let's say I just want to display 20 at a time and page through all the results. Would I have the server do the query each time a user clicks on next page or should I have the server get the entire result set and then sent parts of it to the client?
Use a cursor - it is perfect for these purposes.
Note - a report with million rows is not well designed report. Nobady can process it. But this is question for analytic.
http://www.commandprompt.com/ppbook/x15040
I used Limit in sql query to set a range of records fetched. but the query has to originate from client and the query must pass the range.
It depends on scripting, if you use Dotnet+npgsql connector
I would generate a Pagenumber in a combobox on form
Then multiply the pagenumber with Rows*(pagenum-1) (20*1 for page2) to get starting rownum
Pass it in form of sql to database
Retrieve rows and display in datagridview
Although, i might just add, searching through a million record Page_by_page is not wisdom. i hope there are some filters to narrow down search to a few pages. Because research show that views beyond page10 drop exponentially.

Resources