SQL script for Custom mail body from 2 un-related tables - sql

View StructureI am working on a tool wherein we have to configure a view to send out the custom email notifications to the customers.
I have a view name:
webNotification_Mail_LiqAmt_Workflow which stores email details like
Then I have another table from where I need to bring in the amount which is to be mailed to the customers based on their projects and other parameters.
[enter image description here][2]
I do not need email setup because it is already taken care. I need to pass the amount in the email body so basically I need to get the amount in 'messsge' column of the above view (webNotification_Mail_LiqAmt_Workflow)
I cannot think of a way to built this logic as both the tables are un-related.
Please help.
Design of the view:
**CREATE VIEW [dbo].[webNotification_Mail_LiqAmt_Workflow]
AS
SELECT ID,
Event,
EmailFrom,
Subject,
Message,
'NoReply#xyz.com' AS EmailTo,
'123#rte.com' AS EmailBCC
FROM dbo.webWorkflowNotification_LiqAmt**
I would need custom amounts in the message column based on the parametrers.The view that from where I need the Amounts looks like:
SELECT TOP (1000) [LIQAMTID]
,[Project_Name]
,[Startup]
,[Business_contact_Name]
,[Business_Contact_Email]
,[Sum_Liq_amt]
FROM [webLiqAmt_Mail_Notification]

According to my grasp of the situation I guess what you are looking for is a cross join.By using cross join you could add the two unrelated tables and then later exploit them for your use. I am giving and example,
SELECT username,password,dob,address
FROM basic_details
CROSS JOIN login
where username and password belong to login, and dob and address belong to basic_details.
OR
You can use cartesian product of the two tables.
SELECT * FROM basic_details, login
This would result in M * N rows.
Hope it helps.

Related

How to use loop to find related object using Pentaho Data Integration

I want to identify the bad/invalid records so that i can add in a separate SQL Table. For example, we have an account object. And i want to find bad accounts. But i need to apply some filters on contact object. If conditions satisfy based on contact then i want to inserts those invalid account records in SQL Table.
I don't want to directly query from contact. I want to query using account but conditions should be used from contact.
Do anyone knows what is the best way to perform loop in Pentaho? Check each record for contact , if all contact's condition satisfy then add Account id in table. If one of the contact record doesn't satisfy condition. The relevant account should not be added in SQL Table
For Example:
On Account "A" we have 10 contacts
if the email field is empty on all 10 contacts then add Account in SQL table(As bad data)
if on two of contact rcords has email field populated but 8 of them are blank then Account id shouldn't be added in SQL table
How we can better implement this scenario using Pentaho? Any help matters
Thanks
So you can create a transformation similar to this:
You have a query with the different account contacts
Order the query data by account
Group the information by accounts and calculate the maximum ContactMail (so if all mails in contacts are null, the max will be a null, is the result of that step is shown in the Preview data part of my screenshot)
Filter rows by MaxContactMail IS NOT NULL
These could be the basic steps, you'll need to add more steps or perform more than one transformation depending on the complexity of your data.

SQL query / SQL Reporting Services

Been rattling my brain for a while and I could not get pass how to do the SQL query that will show the relationship/connections between my two tables.
I'm working on an IT equipment inventory program. I have two tables;
SELECT serial_number, model, ship_dat, status FROM items_list
SELECT item_serial, connected-to_serial FROM connections
All items like desktops, laptops, monitors, etc are on the items_list table. To track down the relationship/connections of the items, I created the connections table. IE, Monitor with serial_number=Screen#1 is connected to a Desktop with serial_number=Serial#1. It works ok with my Window Form application because I
used a datagridview control to list all devices simple SQL query.
However, when trying to show the relationship/connection on SQL Reports I've ran out of ideas how to do it. I'm aiming to get the report look like below or something along the lines. I just need to show the connections between the items.
Thank you
You should be able to do this with a table in SSRS if that is what you are using. The query you would need to drive the table of all related items would be:
SELECT item_serial, connected-to_serial, mainItem.*, connectedItem.*
FROM connections
INNER JOIN items_list mainItem ON connections.item_serial = items_list.serial_number
INNER JOIN items_list connectedItem ON connections.connected-to_serial = connectedItem.serial_number
You can of course tailor the SELECT statement to your needs, mainItem.* and connectedItem.* will not give you the most descriptive column names. Using column aliases (found under column_alias here) you can give a more descriptive name to each column.
From here you should be able to use a table and create a row group on the main item (either name or serial number) to get the type of look you are looking to achieve here. I believe the Report Wizard actually has most of the functionality you are looking for and should handle the bulk of this. You may have to move some of the cells around to get the look you are going for though.

How to use FOR EACH type functionality in a SQL query?

I have a report that returns a page for a specific order using that orders information. My users want to be able to select multiple orders, and be able to scroll through. I changed the parameter to select multiple values and populated the list with a query to show all orders.
My problem is that when I select multiple orders, it throws all the information from all the orders on to one sheet, whereas I want it to return the page with information for each specific order on a different page.
Is there a FOR EACH/loop type functionality I can incorporate to run this in interation?
Let me know if you need pictures or code. Here's what I essentially have now:
SELECT
info
FROM table
WHERE conditions
AND order_no in (:OrderNo)

When relating 3 entities in CRM 2011 using Advanced Find only 2 entities show up in edit columns

I'm trying to create a view in CRM 2011 that will show a few columns from Customers (Account), Orders (SalesOrder), and Order Products (SalesOrderDetail). I already know I need to start at the child-most entity so under Advanced Find I select "Order Products" under Look for. When I do this I'm able to select columns from Orders but unable to select columns from Customers.
Is this even possible to accomplish in CRM?
I'm trying to create the following result set:
Account.Name,
Account.Email,
SalesOrder.OrderNumber,
SalesOrderDetail.NetAmount,
SalesOrderDetail.ShipDate
I verified that you cannot manually add a second link within a view query. To my knowledge it is also not possible to add these columns though javascript. You can get the account name in your view simply by using the account lookup on the Order. If you need for the account email to also be in the view, then I suggest you add this field to the order entity and populate it with post callout logic on the account.
I Second Zach’s idea, but suggest adding a direct relationship between customer and orderdetail . This way you can use fetchxml to show account.email or any other account.* for that matter.
The downside is you’ll need to sync order.customer changes to orderdetail.customer.
The better option is to simply create a report and show that in an iframe or a webresource.
This is not possible even if we edit the fetch xml it wont work

SQL INSERT with Inner Join

I Have a Table (Accommodation) with All information about a holiday home. Inc ID Name etc.
I have another Table (Schedule) with a Schedule ID, Date and Price
I have a final table to join the two (SchdAccom) with A schdaccom id, the AccomodationID and Schdule ID.
What this allows is me to add dates a holiday home is available for use by linking its id with an id of a date and 1 home can link with many dates/price.
Heres my issue I can query this fine no problem works great but im unsure how to go about inserting new ones. For instance, at the moment you as an admin select the holiday home click a button to see the dates and a gridview pulls this info. I want to be able to add more dates but the tableadapter wont generate insert code.
Any idea on how to go about this?
The best method would be to generate SQL that would inject data into both tables when you submit the request. Because you're working with 2 different tables, you're going to have to write a bit of manual code.