SSIS Send email Task With Variables - email

I was asked to send an email to my employees with the following info that I have:
Excel File (EmployeeInfo):
EmpID EmpName Rank PromoGift
1 Peter 5 1
2 Armand 4 2
3 Tommy 5 5
4 Sarah 2 4
5 Maria 3 3
CSV File (PromoCode):
PromoID Validation
1 1
2 0
3 1
4 1
5 0
Text File (PromoInfo)
PromoID Gift
1 100$ Apple GC
2 80$ Apple GC
3 60$ Apple GC
4 40$ Apple GC
5 20$ Apple GC
Requirements:
1. Only employees that has Validation = 1 will receive a gift.
2. The gift is based on the PromoID (PromoGift)
3. "Data Flow Task, Execute Sql Task, ForEach Loop & Send Mail" Task can only be used to execute the task above.
4. In the email, I need to replace the [...] accordingly.
5. Employee's email are neglect in this exercise.
I will send an email to them with the following message:
Dear [EmpName],
This [CurrentYear], during our [EventName], you have been selected to be the winner for reaching your next level Rank [Rank]. You will receive a [Gift]!
A gift from your Manager [Manager]!
Congratulation!
What should I do (I am new to SSIS)?
Create 3 Data Flow Task and load each files into SQL Server Table. Then Use SQL Task to do a Join, so I can get the list of who will receive the gift, then what's next? And what should I use to insert those variables into my email template? I believe I need to creates variables too.
Any thoughts?

Check This.
1.First load each files into SQL Server Tables
EmployeeInfo , PromoCode , PromoInfo
2.Open SQL Server and You need to create a profile and account using the Configure Database Mail Wizard which can be accessed
from the Configure Database Mail context menu of the Database Mail node in Management Node.
This wizard is used to manage accounts, profiles, and Database Mail global settings
Query to send mail
USE msdb
GO
EXEC sp_send_dbmail #profile_name='yourprofilename',
#recipients='test#Example.com',
#subject='Test message',
#body='This is the body of the test message.
Congrates Database Mail Received By you Successfully.'
4.
DECLARE #email_id NVARCHAR(450)='1', #id BIGINT, #max_id BIGINT, #query NVARCHAR(1000)
SELECT #id=MIN(id), #max_id=MAX(id) FROM [EmployeeInfo ]
WHILE #id<=#max_id
BEGIN
SELECT #email_id=email_id ,#Gift =gift
FROM EmployeeInfo e join PromoInfo p on p.id = e.id
where ID= #id
SET #body = N''+#email_id+'Your Gift Is' +#Gift;
SET #body = #body
EXEC msdb.dbo.sp_send_dbmail
#profile_name = 'Profile_Name',
#body = #body,
#body_format ='HTML',
#recipients = #email_id,
#copy_recipients = '',
#subject = 'Subject' ;
SELECT #id=MIN(id) FROM [EmployeeInfo ] where id>#id
END
You can use these example and also create SP for that. and call this SP in Your SSIS package.

Related

PostgreSQL: How to check if a list is contained in another list?

I'm working with PostgreSQL 13.
I have two tables like this:
permission_table
name
permission
Ann
Read Invoice
Ann
Write Invoice
Ann
Execute Payments
Bob
Read Staff data
Bob
Modify Staff data
Bob
Execute Payroll
Carl
Read Invoice
Carl
Write Invoice
risk_table
risk_id
permission
Risk1
Read Invoice
Risk1
Write Invoice
Risk1
Execute Payments
Risk2
Read Staff data
Risk2
Modify Staff data
Risk2
Execute Payroll
I'd like to create a new table containing the names of the employees of the first table whose permissions are pointed as risks in the second table. After the execution, the results should be like this:
name
risk_id
Ann
Risk1
Bob
Risk2
Since Carl only has two of the three permissions belonging to Risk2, he will not be included in the results.
My first brute force approach was to compare the list of permissions belonging to a risk to the permissions belonging to an employee. If the first list is included in the second one, then that combination of employee/risk will be added to the results table.
INSERT INTO results_table
SELECT a.employee, b.risk_id FROM permission_table a, risk_table b WHERE
((SELECT permission FROM risk_table c WHERE b.permission = c.permission ) EXCEPT
(SELECT permission FROM permission_table d WHERE a.employee=d.employee)
) IS NULL;
I'm not sure if the results could be correct using this approach, because if the tables are big, it takes a very long time even if I add a WHERE clause limiting the query to just one employee.
Could you please help?
One way of approaching this one is by
computing the amount of permissions for each "risk_id" value
joining the "permissions" and "risks" table with counts on matching "permission" values
making sure that the distinct count of permissions for each triplet "<permissions.name, risks.risk_id, risks.cnt>" corresponds to the full amount of permissions.
WITH risks_with_counts AS (
SELECT *, COUNT(permission) OVER(PARTITION BY risk_id) AS cnt
FROM risks
)
SELECT p.name, r.risk_id
FROM permissions p
INNER JOIN risks_with_counts r
ON p.permission = r.permission
GROUP BY p.name, r.risk_id, r.cnt
HAVING COUNT(DISTINCT r.permission) = r.cnt
Carl won't be included in the output as he doesn't have all permissions from "risk_id = 'Risk 1'"
Check the demo here.

Split multiple times in Tableau for Join Condition (Datasource or Worksheet)

I have two EXCEL files and trying to use the customer id from one file to match the customer id's that are included as a part of 2nd file which includes a 300 character. The Customer id in the second file is embedded as a part of the 300 characters.
I need to find-out how I can take the customer ids from the first file (customer file) to join them with the second file that includes the customer transactions.
I can use the Datasource Join options and establish one condition such as below,
Customer ID = SPLIT([Field Number],"_",1) but since this condition is not enough and I need multiple SPLITS to get the customer ID based on other conditions using SPLIT, it is not working within the DataSource Tab-> Join Options.
HOW CAN I DO MULTIPLE SPLITS like
Customer ID = SPLIT([Field Number],"",1) OR Customer ID =
SPLIT([Field Number],"GET",6) OR Customer ID = SPLIT([Field
Number],"TEACH",1)
If I need to do this within the Worksheet, using the calculated field, please let me know how I can use the Calcuated Field option but include all the conditions..
Thanks in advance for your time
Customer File:
Picture of the firest file includings the Customer IDs
Transction file:
enter image description here

use executeSQL() to populate portal in Filemaker

I have a client with a Filemaker 16 app that uses an ODBC connection to a SQL Server DB. With Filemaker, everything I know about databases seems to be wrong. I have wrestled for 2 days with this and only ask as a last resort --- is it possible to populate a portal field with the results of a SQL query? I am trying to return unique records and exclude duplicates. Where would the executeSQL() call go? I thought perhaps in the Filter on the Portal, but that is not it. Sorry for the basic question.
A FileMaker portal will always show the records matching a given relationship in the Relationship graph. This set of records can be further constrained by the portal filter.
To achieve a list of unique items, you will need to create a calculation field in your related table that determines if the record is unique. This can be done in many ways, ExecuteSQL being one. You can then use this field as a predicate in the relationship itself or use it in the portal filter.
This is just one way to do it.
In the (shadow) table you want to display record from, create a calculation field that returned 1 if the record should be included and 0 if it should be omitted. It might be something like this:
Let (
[
_sql = List (
"SELECT id" ;
"FROM table" ;
"WHERE match_field = ?" ;
"ORDER BY id" ;
"FETCH FIRST 1 ROW ONLY"
) ;
_id = ExecuteSQL ( _sql ; "" ; "" ; match_field )
] ;
_id = id
)
Now in the table you want to show a portal from, create a global calculation field, ONE that returns 1 and then create a relationship between that table and the one you want to view a portal of using ONE and the SQL calc above as the match fields.
On a layout with a context into the LAYOUT_CONTEXT table above, you can create a portal into SHADOW_TABLE.

Filemaker Pro: How can I limit exported records returned from a layout with a portal?

I'm creating a database for a small magazine in Filemaker Pro 14. Each subscriber can have multiple subscription records, so in the 'Subscriber' layout, I have inserted a portal which shows the list of related subscription records for the subscriber I'm viewing.
When I run a Find operation to view only current subscribers and then export this as a CSV (adding the subscription start and end date as an exported field), I get a list of all current subscribers, but also all the subscription records for each one. I want to limit this so that I only get the current, active subscription record for each subscriber. It looks like this:
ID, firstname, lastname, address, city, state, zip, begin_issue, end_issue
1, John, Doe, 123 Anystreet, Anytown, ST, ZIP, 32.4, 33.3
, , , , , , , 33.4, 34.3
, , , , , , , 34.4, 35.3
I just want to get:
ID, firstname, lastname, address, city, state, zip, begin_issue, end_issue
1, John, Doe, 123 Anystreet, Anytown, ST, ZIP, 34.4, 35.3
I have created a layout with a portal that includes a filter which only returns the active subscription. However when I export from this layout, I get exactly the same result - it includes all related records.
Thanks for any thoughts on this.
I want to limit this so that I only get the current, active
subscription record for each subscriber.
Exports work at the data layer, so it doesn't matter what you have on the layout. You can have a filtered portal, or no portal at all; still, when you include a related field in the export field order, data from all related records will be exported.
To export all (and only) current subscriptions, do your export from the Subscriptions table, after finding only current subscriptions, and include the necessary fields from the Subscribers table.
Simply duplicate this layout, move the fields from the related table directly onto the layout itself, then delete the layout. Only fields from the first related record will be exported. (If you don't get the related record you want, you'll need to adjust the sort order of the relationship you're using).

Drupal Simplenews - How to subscribe all existing users?

Registered users were created first, then Simplenews was added.
How to set up mailing to all already registered users?
I get that you can send emails only to those who joined after you install the module. But I need the existing users' addresses included also.
I found a solution only cure addresses from the database, then export, and put them in a mass subscription.
I just did the following successfully on an up-to-date Simplenews module, with a 3000+ user base. The answer comes from http://cc.com.au/2010/02/03/drupal-simplenews-mass-subscribe
So what I do first is select the uid and email address for all authenticated users (the anonymous user has uid 0, so I select only users with a higher uid) and insert those into the simplenews_subscriptions table.
INSERT INTO simplenews_subscriptions(activated,mail,uid) SELECT 1,mail,uid FROM users WHERE uid > 0 ORDER BY uid ASC;
This automatically assigns a snid (subscription id) to each entry. You'll notice that rather than selecting a column value into the activated field, I just set it to 1.
Next, I need to find the taxonomy term ID (tid) for the particular newsletter to which I want to subscribe all users. You can find this either by listing the terms in the Newsletter vocabulary or by listing all newsletters. In both cases the term id will be shown in your web browser's status bar if you hover the mouse over the edit link: http://example.com/admin/content/simplenews/types/edit/42
On my Drupal site the tid is 42, so that is the newsletter number I want to subscribe my users to. I need to refer to them via the automatically assigned snid from the simplenews_subscriptions table, so I select that and insert it directory into the simplenews_snid_tid table, together with the correct tid.
INSERT INTO simplenews_snid_tid(snid,tid) SELECT snid,42 FROM simplenews_subscriptions;
D7 Solution
To add all users that are not already subscribers run this query
insert into simplenews_subscriber(activated, mail, uid) select 1, mail, uid from users where uid not in (select uid from simplenews_subscriber) and uid > 0;
And to subscribe them to a newsletter run this query
insert into simplenews_subscription(snid, tid, status, timestamp, source) select snid, 31, 1, unix_timestamp(), 'manual' from simplenews_subscriber where snid not in (select snid from simplenews_subscription);
Remmember to replace the number 31 by the number of your newsletter.
You should be able to implement this using Views, VBO and Rules.
Create a view that lists your users (with filters, if you want), create a rules component that receives a user as argument and then subscribe the mail address of that user using the provided action (make sure you've enabled the simplenews rules module).
Then enable bulk operations on the view with that rules component.
Credit #Berdir https://www.drupal.org/project/simplenews/issues/1564988