How to send an email from a query result having more than one line - azure-logic-apps

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:

Related

SSRS pass through Delivery Options

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!

Mule Salesforce connector in query operation. List of Maps as input

I have a huge list of Ids and Names for Contacts defined in this simple DW script. Let's show just two for simplicity:
[
{id:'169057',Name:'John'},
{id:'169099',Name:'Mark'}
]
I need salesforce connector to execute a single query (not 1000 unitary queries) about this two fields.
I expect the connector to be able to use a List of Maps as input, as it does using update/insert operations. So, I tried with this Connector config:
I am getting as response a ConsumerIterator. If I do a Object to String transformer but I am getting an empty String as response.
I guess must be a way of executing a big query in just one API call... But I am not finding it. Have in mind I need to use two or more WHERE clauses.
Any idea? Thanks!
I think you need to create two separate list for id and Name values from your input and then use those list in the query using IN.
Construct id list to be used in where clause. This can be executed inside for each with batch size 1000.
Retrieve name and id from contact for each batch
select id, name from contact where id in (id list)
Get the desired id's by matching name retrieved in step 2 within mule.

Can SSIS create output spreadsheet based on value of field in Input

A department in my company gets a report every day as a a spreadsheet of invalid debit cards. It can contain 0 to hundreds of different clients. The client ID is a column on the spreadsheet. They have to take the records for Client A, make a spreadsheet called, say Client_A_20170602.xlsx and email that to client A. Then they have to do the same for client B. If there are just a few clients then it is not a big deal to do it manually, but today they had 115 different clients. They want to know if I can write an SSIS package that will automate this process.
I could bring the spreadsheet into an SQL table, do a SELECT DISTINCT on the Client ID, put the results into a temp table, go through each client on the temp table, get their records, and put them into a date stamped table. I could then (back in SSIS) use a FOR EACH loop to look for files that contain the date stamp and write them out to spreadsheets.
Can this work? Can somebody suggest a better solution?
Thanks,
Dick
Another solution would be an SSRS Report with each client getting a subscription that emails them their data.

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.

proper way of updating sql server table using access front end

i have a front end in access and back end is sql server 2008
one of the fields is the account number and here are the rules
it is a zipcode like 92111 plus a dash plus a number.
so the first one would be 92111-1, the second 92111-2
this has to do with how many clients we have in the zip code
i would like this zip code to be automatically generated. here is what i need:
the user enters the zip code
i have a stored procedure that checks if this zip code exists already, to increment it: if 92111-4 exists already, then make it 92111-5.
what is the proper way of doing this?
If you're storing both the zip and the client sequence number in a single account number field, you would have to split them apart to figure out the next sequence number in a given zip code.
It should be simpler to store them in 2 fields:
zipcode sequence_num
92111 4
92111 5
Then derive your account number field with a query whenever you need it.
SELECT zipcode & "-" & sequence_num AS acct_num
FROM YourTable;
Then when you need to determine the next sequence_num, lngNextSequenceNum, within a given zipcode, pZip:
lngNextSequenceNum = DMax("sequence_num", "YourTable", "zipcode = " & pZip) +1
That approach can work fine for a single user application. If your application is multi-user, you need something more refined. However, that requirement exists whether you store "account number" as a single field or split it between two fields.
See Create and Use Flexible AutoNumber Fields for a multi-user approach.
I agree with HansUp that you should keep the ZIP and sequence separated. You can create an indexed computed field called AccountNumber which joins the zip and sequence.
The only way I know of doing this is locking the table, selecting max(sequence) ... where ZIP = 12345, inserting the new record, then unlocking the table. However, locking the table means everyone else has to wait, greatly affecting scalability. I can't recommend this, but I don't have another solution.

Resources