I have a report that I generate weekly that shows contracts being expired or soon to be expired within 90-days. The report works fine, however, the contracts or sites that are NOT out of contract or soon to be expiring are still appearing as headers on the report. My question is, how do I ONLY show the sites expired and due to expire and not the other sites (headers, names, etc...).
SITE_INFO
===========================================================
SELECT SITE.ID SITE_INFO_ID,
"ORGANIZATION"."NAME" "CUSTOMER_NAME",
"SITE"."NAME" "SITE_NAME",
"CUSTOM"."VALUE" "MANAGER_NAME",
"ADDRESS"."ADDRESSLINE1" AS "ADDRESSLINE1",
"ADDRESS"."ADDRESSLINE2" AS "ADDRESSLINE2",
"ADDRESS"."ADDRESSLINE3" AS "ADDRESSLINE3",
"ADDRESS"."CITY" AS "CITY",
"ADDRESS"."STATE" AS "STATE",
"ADDRESS"."COUNTRY" AS "COUNTRY",
"ADDRESS"."POSTAL_CODE" AS "POSTAL_CODE",
"ADDRESS"."SITE_ID" AS "SITE_ID",
"REGION_CODE"."ID" AS "REGION_ID",
"REGION_CODE"."NAME" AS "REGION_NAME"
FROM ORGANIZATION,
SITE,
CUSTOM,
ADDRESS,
REGION_CODE
WHERE SITE.ORGANIZATION_ID = ORGANIZATION.ID AND
CUSTOM.SITE_ID = SITE.ID AND
CUSTOM.NAME LIKE 'MANAGER NAME' AND
SITE.ID = ADDRESS.SITE_ID AND
REGION_CODE.ID = SITE.REGION_ID AND
SITE.IS_DELETED = 0
SYS_DATE
=============================================================
SELECT TO_CHAR(SYSDATE,'MM-DD-YYYY') FROM DUAL
CONTRACT_INFO
=============================================================
SELECT CONTRACT_TYPE.NAME CONTRACT_NAME,
CONTRACT.SITE_ID SITE_ID,
CONTRACT.CONTRACT_INDEX CON_INDEX,
TO_CHAR(CONTRACT.END_DATE,'MM-DD-YYYY') END_DATE,
CONTRACT.ORDER_NO ORDER_NO,
CONTRACT.PROJECT_NO PROJECT_NO,
CASE WHEN CONTRACT.END_DATE <= SYSDATE THEN 1 ELSE 0 END FLAG
FROM CONTRACT LEFT JOIN
CONTRACT_TYPE ON CONTRACT.CONTRACT_TYPE_ID = CONTRACT_TYPE.ID
WHERE CONTRACT.SITE_ID = :SITE_INFO_ID
AND CONTRACT.END_DATE <= SYSDATE + 90
The SITE_INFO and CONTRACT_INFO data sets are linked, and the template is created in MS Word using BI Publisher. Code is written in SQL in BI Publisher online.
This could be a little more than you need, but would work.
Repeat Site section for each site. Each section starts a new page.
Count number of expired contracts within site, with unique order numbers.
Only show site if number of expired contracts is more than zero.
Site content
Within site content, show count of expired contracts (optional)
Repeat contract section, only for contracts that are expired.
Assuming you have data structure:
EXTRACT/LIST_SITE_INFO/SITE_INFO/LIST_CONTRACT_INFO/CONTRACT_INFO
XML Like:
<EXTRACT>
<SYS_DATE>2015-05-15 8:30:25</SYS_DATE>
<LIST_SITE_INFO>
<SITE_INFO>
<CUSTOMER_NAME>Test Customer</CUSTOMER_NAME>
<CUSTOMER_ID>123</CUSTOMER_ID>
<SITE_NAME>Test Site</SITE_NAME>
<LIST_CONTRACT_INFO>
<CONTRACT_INFO>
<CONTRACT_NAME>Contract 123</CONTRACT_NAME>
<ORDER_NO>456</ORDER_NO>
<CONTRACT_ID>789</CONTRACT_ID>
<FLAG>1</FLAG>
</CONTRACT_INFO>
</LIST_CONTRACT_INFO>
</SITE_INFO>
</LIST_SITE_INFO>
</EXTRACT>
Template would looks something like this:
<?for-each#section:EXTRACT/LIST_SITE_INFO/SITE_INFO?>
<?xdoxslt:set_variable($_XDOCTX, ‘V_EXP_COUNT’, count(xdoxslt:distinct_values(//LIST_CONTRACT_INFO/CONTRACT_INFO[FLAG="1"]/ORDER_NO)))?>
<?if:xdoxslt:get_variable($_XDOCTX, ‘V_EXP_COUNT’)>0?>
Site Section / Content
Number of Expired Contracts: <?xdoxslt:get_variable($_XDOCTX, ‘V_EXP_COUNT’)?>
<?for-each:LIST_CONTRACT_INFO/CONTRACT_INFO[FLAG="1"]?>
Expired Contract Section / Content
<?end for-each?>
<?end if?>
<?end for-each?>
Make sure there's no spaces/new-lines between the elements in the template.
Related
We extend contractor term date in OIM to 80 days but some times it gets extended by admins/managers more than 80 days. When it gets extended, OIM creates a request id. Now, we would like to know all the users who term date is more than 80 days from the day(request creation date) they got extended.
Is there a way to get the details of the users and the request creation date that happened on termination date attribute in a SQL query so that we can create a BI report.
As i have a requestid which was created yesterday i am using it for developing the query. I tried below query by joining usr, request and request_beneficiary tables but it doesn't return anything. Are there any other tables which i need to use to accomplish this use case.
-- Even try with specific requestid req3.request_id=123456
-- Tried with the request id's beneficiary key too.
SELECT
req3.request_key rk,
usr2.usr_login buid,
usr2.usr_status,
req3.request_creation_date,
req3.request_model_name,
to_char(usr2.usr_udf_terminationdate, 'MM-DD-YYYY') AS Terminationdate
FROM
request req3,
request_beneficiary reqb1,
usr usr2
WHERE
req3.request_key = reqb1.request_key
AND beneficiary_key = usr2.usr_key
and usr2.usr_status = 'Active'
AND usr2.usr_emp_type IN ( 'Contractor');
If anyone has done this type of use case. can you please provide your inputs.
Appreciate your inputs and suggestions
Thanks in advance.
I'm sure you've already figure this out, but here is some SQL that should get you to the data you need.
SELECT r.request_key rk,
R.Request_Creation_Date,
Red.Entity_Field_Name,
Red.Entity_Field_Value,
usr_status,
usr_end_date,
usr_udf_terminationdate
FROM request r
INNER JOIN Request_Entities re
ON R.Request_Key = re.request_key
INNER JOIN Request_Entity_data red
ON re.request_entity_key = red.request_entity_key
INNER JOIN usr
ON Re.Entity_Key = usr.usr_key
WHERE request_model_name = 'Modify User Profile';
I have one table, Main, which is the main accounting table with all the transactions. I have a second table, Payments, which i keep track of payments and specifically which invoice a given payment has paid off.
I need a report that will be dynamic and flexible; really my accounting workhorse. The report i need will search between dates, customer Id's, record status, account1, account2, and pay status.
So i have a form built out to handle these inputs, but i am having trouble with "pay status" as in, how to form a parameter with it. My current code,
SELECT Main.Invo, Main.InvoDate, Main.Amt, Main.PartyId, Main.TboInvoRloc, Main.TboDocNo, Main.TboPax
FROM Main
WHERE Main.RecSrce<>"Accounts"
AND Main.InvoDate BETWEEN [Forms]![GeneralReport]![startDate] AND [Forms]![GeneralReport]![endDate]
AND Main.PartyId =IIF([Forms]![GeneralReport]![PartyID] IS NULL, PartyID, [Forms]![GeneralReport]![PartyID])
AND Main.Status = IIF([Forms]![GeneralReport]![Status] IS NULL, Status, [Forms]![GeneralReport]![Status])
AND Main.Ac1 = IIF([Forms]![GeneralReport]![Ac1] IS NULL, Ac1, [Forms]![GeneralReport]![Ac1])
AND Main.Ac2 = IIF([Forms]![GeneralReport]![Ac2] IS NULL, Ac2, [Forms]![GeneralReport]![Ac2])
;
covers everything but the "pay status." I wanted to do something like
If checkbox=true, then include paid items, else exclude items where Main.Invo = Payments.DueInvo
My other thought was to exclude the paid items in the initial query, and then include them in a subsequent union query if the checkbox is checked. Any help or thoughts would be appreciated.
Set unbound checkbox for TripleState Yes. Or use a combobox with 3 options (Paid, Unpaid, All) because users might be confused by a triple state checkbox.
Build an aggregate query on Payments table that totals the payments by invoice. Join that query to Main (this assumes invoice is unique in Main).
Calculate a field and set a parameter under that field.
If using checkbox:
IsNotPaid: Amt <> Nz(SumOfPayments,0)
LIKE Forms![GeneralReport]!checkboxname & "*"
If using combobox:
PaidStatus: IIf(Amt = Nz(SumOfPayments,0), "Paid", "Unpaid")
LIKE IIf(Forms![GeneralReport]!comboboxname = "All", "*", Forms![GeneralReport]!comboboxname)
An alternative to aggregate query is DSum() domain aggregate function but that will probably perform slower.
Consider setting payment detail columns to NULL depending on checkbox. Specifically, join the Payments table and run a logical condition on fields in SELECT assigning NULL or not.
SELECT m.Invo, m.InvoDate, m.Amt,
m.PartyId, m.TboInvoRloc,
m.TboDocNo, m.TboPax,
IIF(Forms]![GeneralReport]![myCheckBox] = True,
p.PaymentDetailColumn1, NULL) AS PayColumn1,
IIF(Forms]![GeneralReport]![myCheckBox] = True,
p.PaymentDetailColumn2, NULL) AS PayColumn2,
IIF(Forms]![GeneralReport]![myCheckBox] = True,
p.PaymentDetailColumne, NULL) AS PayColumn3
...
FROM Main m
LEFT JOIN Payments p ON m.Invo = p.DueInvo
WHERE m.RecSrce <> 'Accounts'
AND m.InvoDate BETWEEN [Forms]![GeneralReport]![startDate]
AND [Forms]![GeneralReport]![endDate]
AND m.PartyId = NZ([Forms]![GeneralReport]![PartyID], m.PartyID)
AND m.Status = NZ([Forms]![GeneralReport]![Status], m.Status)
AND m.Ac1 = NZ([Forms]![GeneralReport]![Ac1], m.Ac1)
AND m.Ac2 = NZ([Forms]![GeneralReport]![Ac2], m.Ac2);
If you want dynamic columns (i.e., payment details) to appear or not depending on condition, this cannot come directly from SQL but some connecting app layer code (VBA, Python, etc.) to building dynamic queries. Recall SQL is a declarative language and once identifiers are assigned they are immutable. However, if using reports, you do want all columns explicitly defined from recordsource query.
I have (two) tables of SENT and RECEIVED email messages exchanged between patients and their doctors within an app. I need to group these rows into conversation threads exactly the way you would expect to see them in your email inbox, but with the following difference:
Here, “thread” encompasses all back-and-forth exchanges between the same 2 users. Thus, each single unique pair of communicating users constitutes 1 and only 1 thread.
The following proof-of-concept code successfully creates a notion of “thread” for a single instance where I know the specific patient and doctor user IDs. The parts I can’t figure out are:
(1) how to accomplish this when I’m pulling multiple patients and doctors from tables, and then
(2) to sort the resulting threads by initiating-date
SELECT send.MessageContent, send.SentDatetime, rec.ReadDatetime, other_stuff
FROM MessageSend send
INNER JOIN MessageReceive rec
ON send.MessageId = rec.MessageId
WHERE
( send.UserIdSender = 123
OR rec.UserIdReceiver = 123 )
AND
(send.UserIdSender = 456
OR rec.UserIdReceiver = 456)
If MessageID is unique for a conversion, You can order the messages using the send and received date time.
If you want to filter for particular doctor or patient ,you can include it in the where clause.
SELECT send.MessageContent, send.SentDatetime, rec.ReadDatetime, other_stuff
FROM MessageSend send
INNER JOIN MessageReceive rec
ON send.MessageId = rec.MessageId
ORDER BY send.MessageId,send.SentDatetime, rec.ReadDatetime
I need to convert a manually-created spreadsheet into a SQL report. The report is generated via Oracle Forms (one of the BI Suite apps).
There's an inbox where many tickets come in to, identified by a "Request Number"
Each Request Number is a help desk ticket in the system. Here is a screenshot of that spreadsheet:
A full listing of columns(with descriptions) :
Request No.
Modules
Submitted ( the request being submitted , a timestamp )
Supervisor ( the request being approved , by supervisor )
Average Supervisor Approval Duration
Responsibility
Average Resp. Approval Duration
Training (the request being approved for completing training)
Average Training Approval Duration -
Configuration - depending on whether its PRISM or iProcurement
Average Config. Approval Duration
Approved
Total Overall Duration
Security
Average Security Approval Duration
SOD
Avg SOD Approval Duration
So what I'm trying to do is to generate, some or all, of it using a SQL script.
One of my issues is that .. for a specific "Request Number" I'll often get redundant and conflicting data in the database.
Below is my query so far.
SELECT hur.reg_request_id AS "Request No",
RESPONSIBILITY_NAME AS "Module",
to_char(hur.creation_date, 'DD-Mon-YYYY HH24:MI:SS') AS "Submitted" ,
to_char(hur.last_update_date, 'DD-Mon-YYYY HH24:MI:SS') AS "Supervisor" ,
ROUND((hur.last_update_date - hur.creation_date), 3 ) ||
' days' AS "Avg Supervisor Appr Duration" ,
/* hura.creation_date AS "Responsibility" */,
NULL AS "Avg Resp Appr Duration", NULL AS "Training",
NULL AS "Avg Training Appr Duration" ,
hur.LAST_UPDATE_DATE AS "Security",
NULL AS "Avg Security Appr Duration",
NULL AS "SOD",
NULL AS "Average SOD Approval Duration" ,
NULL AS "Configuration",
NULL AS "Avg Config Appr Duration",
hurr.last_update_date AS "Approved",
ROUND( hurr.last_update_date - hur.creation_date, 2 )
AS "Total Overall Duration",
NULL AS "Notes"
FROM HHS_UMX_REG_SERVICES hur
JOIN fnd_responsibility_vl frt
ON (hur.responsibility_id = frt.responsibility_id and
hur.responsibility_application_id = frt.application_id)
JOIN
hhs_umx_reg_requests hurr ON
(hurr.reg_request_id = hur.reg_request_id )
/* JOIN hhs_umx_resp_activity hura */
left outer JOIN
hhs_umx_resp_activity
hura ON (hur.reg_request_id = hura.reg_request_id )--ADD ON
WHERE EXISTS (
SELECT NULL FROM hhs_umx_resp_activity hura
WHERE hura.created_by = hur.created_by
AND
hura.creation_date > hur.creation_date)
AND hur.reg_request_id IN
('263428', '263458', '263473',
'264717', '263402', '263404',
'262671', '263229', '263268')
ORDER BY hur.reg_request_id ASC
Here are the schemas :
HHS_UMX_RESP_ACTIVITY
HHS_UMX_REG_SERVICES
fnd_responsibility_vl
**hhs_umx_reg_requests **
thanks
As a simple solution you can just create rows that add the columns together in an SQL command. Something like "INSERT INTO TABLE ('REQ_NO', 'MODULE') VALUES (A2, B2)" etc. Then you can just use the excel function that copies it again and again for each row.
Another simple solution is to save the spreadsheet as CSV (play around with the exact CSV format to see what suits you) and then you might be able to just import it into your SQL table and play around there.
There are of course other more advanced solutions like TommCatt pointed out.
I have done this many times using Perl. There are packages for reading spreadsheets so just write the script to generate the insert statements needed. Then just write it into a nice .SQL text file which can then be executed by SQL Developer or whatever IDE you're using. Or just execute it directly from the Perl script.
It is hard to diagnose without sample tables (with only a few rows) reproducing the issue.
I think your duplicate data comes from a wrong join.
You could try to completely remove hhs_umx_resp_activity from the query (I see that you commented places where it is used).
Then if it continues it has to be related to the join on hhs_umx_reg_requests (you might be able to join an additional column or replace this join by something else, an outer apply for example).
I have a system that will allow users to send messages to thier clients. I want to limit the user to x amount of messages per day/week/month (depending on subscription). What is a good way to tally for the time period and reset the tally once the time period restarts? I would like to incorporate some sort of SQL job to reset the tally.
Each time you send a set of messages, log the date and the number of messages sent. Your application can then sum the message count fields, grouping by either the day, the week of year, or the year of the date to enforce limits. The where clause used to limit the user to a specific number would use a message limit, start date, and stop date from the user profile table, or some global settings table.
In MySql dialect, you would write something like this:
select
users.id,
(users.msg_limit - subq.msgs_used) as msgs_available
from users
inner join (select
sum(msg_log.cnt) as msgs_used
from msg_log
where weekofyear(msg_log.date) = weekofyear(now())
and msg_log.user = :user_id_param) as subq;
table limits (id, client_id, limit_days, msg_count);
Assume limits count from midnight, Sunday, and 1st of the month.
New clients get three records, one each for limit_days of 1, 7, and 31.
Cron job to run at midnight resets
msg_count = DayLimit where limit_days = 1;
msg_count = WeekLimit where limit_days = 7 and weekday(current_date) = 1
msg_count = MOnthLimit where limit_days = 31 and day(current_date) = 1
Sending message is allowed if min(msg_count) > 0 where client_id = '$client_id'
then send msg and update limits set msg_count = msg_count - 1 where client_id = '$client_id'