Mysql Rollup repeatingid field - mysql

I have the following query result using group by with rollup:
Divison Department Section Employee Name Employee ID Hours
Assets Asset Strategy Not Defined Monty Mouse 480193 64.00
Assets Asset Strategy Not Defined Frank Flint 480165 67.50
Assets Asset Strategy Not Defined 480165 131.50
Assets Asset Strategy 480165 131.50
Assets Event Centre Not Defined Sally Spoons 800192 72.00
Assets Event Centre Not Defined Randolph Smith 800199 37.50
Assets Event Centre Not Defined Petra Peters 800195 64.00
Assets Event Centre Not Defined 800195 173.50
Assets Event Centre 800195 173.50
What I want to be able to do is to stop the employee id from replicating in the rollup lines:
Divison Department Section Employee Name Employee ID Hours
Assets Asset Strategy Not Defined Monty Mouse 480193 64.00
Assets Asset Strategy Not Defined Frank Flint 480165 67.50
Assets Asset Strategy Not Defined 131.50
Assets Asset Strategy 131.50
Assets Event Centre Not Defined Sally Spoons 800192 72.00
Assets Event Centre Not Defined Randolph Smith 800199 37.50
Assets Event Centre Not Defined Petra Peters 800195 64.00
Assets Event Centre Not Defined 173.50
Assets Event Centre 173.50
I've read other posts about using union to try to just match up the employee if from a non-rollup query, but this hasn't worked for me.
I've also read about using sub-select (wrapping) to get the employee id, but this has just lead to the same result.
My rollup statement groups by division, department, section and employee name. If I try to add employee id to this clause I get a rollup on every change of employee. I've also changed the order of the name and if fields and tried grouping by the id rather than the name, but this has just replicated the name in the same way the id is above.
Am I chasing the impossible dream here? Is it not actually possible to display the data in this way? Any suggestions would be greatly appreciated.
For those that would like the full query code, here it is:
select distinct
hr_func_desc('CD_DEPT_', p.department) as 'Department',
hr_func_desc('CD_DIVN_', p.division) as 'Division',
hr_func_desc('CD_SECT_', p.section) as 'Section',
pe.payroll_name as 'Employee Name',
pe.employee_id as 'Employee ID',
max(e.termination_date) as 'Termination Date',
sum(ph.ordinary_hours) as 'Ordinary Hours',
sum(ph.overtime_1_hours) as 'Overtime 1 Hours',
sum(ph.overtime_2_hours) as 'Overtime 2 Hours',
sum(ph.overtime_1_hours) + sum(ph.overtime_2_hours) as 'Total Overtime Hours',
sum(ph.ordinary_hours) + sum(ph.overtime_1_hours) + sum(ph.overtime_2_hours) as 'Total Hours Worked',
sum(al.units) as 'Number of Standby Worked',
sum(ph.statutory_hours) as 'Statutory Holidays',
sum(ph.annual_leave_hours) as 'Annual Leave',
sum(ph.long_service_leave_hours) as 'Long Service Leave',
sum(ph.special_leave_hours) as 'Special Leave',
sum(ph.time_in_alt_hours) as 'Alt Lieu',
sum(ph.parental_leave_hours) as 'Parental Leave',
sum(ph.sick_hours) as 'Sick',
sum(ph.domestic_leave_hours) as 'Domestic',
sum(ph.bereavement_hours) as 'Bereavement',
sum(ph.acc_week_1_hours) as 'ACC Week 1',
sum(ph.acc_hours) as 'ACC Unpaid',
sum(ph.lwop_hours) as 'Leave Without Pay',
sum(ph.sick_hours) + sum(ph.domestic_leave_hours) + sum(ph.bereavement_hours) + sum(ph.annual_leave_hours) + sum(ph.statutory_hours) +
sum(ph.special_leave_hours) + sum(ph.long_service_leave_hours) + sum(ph.time_in_lieu_hours) + sum(ph.time_in_alt_hours) + sum(ph.lwop_hours) +
sum(ph.standby_leave_hours) + sum(ph.parental_leave_hours) + sum(ph.acc_week_1_hours) + sum(ph.acc_hours) as 'Total Hours Absent',
sum(ph.ordinary_hours) + sum(ph.overtime_1_hours) + sum(ph.overtime_2_hours) + sum(ph.statutory_hours) + sum(ph.annual_leave_hours) +
sum(ph.long_service_leave_hours) + sum(ph.special_leave_hours) + sum(ph.time_in_alt_hours) + sum(ph.sick_hours) + sum(ph.domestic_leave_hours) +
sum(ph.bereavement_hours) + sum(ph.acc_week_1_hours) as 'Total Hours Paid',
hr_func_normal_hours(pe.employee_id) as 'Normal Hours Worked per Week',
sum(cast(pt.pay_weeks as unsigned integer)) as 'Pay Weeks for Period Chosen',
round((sum(ph.ordinary_hours) + sum(ph.overtime_1_hours) + sum(ph.overtime_2_hours) + sum(ph.sick_hours) + sum(ph.domestic_leave_hours) +
sum(ph.bereavement_hours) + sum(ph.statutory_hours) + sum(ph.special_leave_hours) + sum(ph.time_in_lieu_hours) + sum(ph.time_in_alt_hours) +
sum(ph.lwop_hours) + sum(ph.acc_week_1_hours) + sum(ph.acc_hours) + sum(ph.standby_leave_hours) + sum(ph.parental_leave_hours))
/sum(cast(pt.pay_weeks as unsigned integer)), 2) as 'Calculated FTE Hours',
truncate(((sum(ph.ordinary_hours) + sum(ph.overtime_1_hours) + sum(ph.overtime_2_hours) + sum(ph.sick_hours) + sum(ph.domestic_leave_hours) +
sum(ph.bereavement_hours) + sum(ph.statutory_hours) + sum(ph.special_leave_hours) + sum(ph.time_in_lieu_hours) + sum(ph.time_in_alt_hours) +
sum(ph.lwop_hours) + sum(ph.acc_week_1_hours) + sum(ph.acc_hours) + sum(ph.standby_leave_hours) + sum(ph.parental_leave_hours))
/sum(cast(pt.pay_weeks as unsigned integer)))/hr_func_normal_hours(pe.employee_id), 3) as 'Calculated FTE'
from swpayroll.py_employees pe
left outer join swhr_rails.hr_employees e on e.id = pe.employee_id
left outer join swhr_rails.hr_employee_positions ep on pe.employee_id = ep.employee_id
left outer join swhr_rails.hr_positions p on ep.position_id = p.id
left outer join swpayroll.py_rep_hist_hours ph on pe.employee_id = ph.employee_id
left outer join swpayroll.py_hist_dedns_allowances al
on al.employee_id = pe.employee_id
and al.pay_date = ph.pay_date
and al.da_id in (33, 66, 67)
left outer join swpayroll.py_hist_totals pt on pt.employee_id = pe.employee_id and pt.pay_date = ph.pay_date
where ep.position_id = (select min(x.position_id) from swhr_rails.hr_employee_positions as x
where x.employee_id = pe.employee_id and x.position_end is null)
and ph.pay_date between '2012-10-21' and '2012-11-04'
group by
hr_func_desc('CD_DEPT_', p.department),
hr_func_desc('CD_DIVN_', p.division),
hr_func_desc('CD_SECT_', p.section),
pe.payroll_name with rollup;
Smaller snippit of code:
select distinct
hr_func_desc('CD_DEPT_', p.department) as 'Department',
hr_func_desc('CD_DIVN_', p.division) as 'Division',
hr_func_desc('CD_SECT_', p.section) as 'Section',
pe.payroll_name as 'Employee Name',
pe.employee_id as 'Employee ID',
sum(ph.ordinary_hours) as 'Ordinary Hours'
from swpayroll.py_employees pe
left outer join swhr_rails.hr_employees e on e.id = pe.employee_id
left outer join swhr_rails.hr_employee_positions ep on pe.employee_id = ep.employee_id
left outer join swhr_rails.hr_positions p on ep.position_id = p.id
left outer join swpayroll.py_rep_hist_hours ph on pe.employee_id = ph.employee_id
left outer join swpayroll.py_hist_dedns_allowances al
on al.employee_id = pe.employee_id
and al.pay_date = ph.pay_date
and al.da_id in (33, 66, 67)
left outer join swpayroll.py_hist_totals pt on pt.employee_id = pe.employee_id and pt.pay_date = ph.pay_date
where ep.position_id = (select min(x.position_id) from swhr_rails.hr_employee_positions as x
where x.employee_id = pe.employee_id and x.position_end is null)
and ph.pay_date between '2012-10-21' and '2012-11-04'
group by
hr_func_desc('CD_DEPT_', p.department),
hr_func_desc('CD_DIVN_', p.division),
hr_func_desc('CD_SECT_', p.section),
pe.payroll_name with rollup;

From what I understand, having posted the same question in the mysql.com forums (http://forums.mysql.com/read.php?10,577674,577674#msg-577674), there is no way to eliminate this repetition at query time.
It would need to be done programatically via a secondary procedural language.

Related

Recursion in Mysql with as

There is a trip table with flights containing columns with the beginning and end of the route. It is necessary to organize a search for a route with several transfers. I can't figure out what my mistake is (error at line 21)?
with RoutesCTE as
(
select concat(airport_from + '->' + airport_to) as Route
,0 as TransfersCount
,airport_from
,airport_to
from trip
union all
select concat(r.Route + '->' + r1.airport_to) as Route
,TransfersCount + 1
,r.airport_from
,r1.airport_to
from RoutesCTE r
join trip r1
on r.airport_to = r1.airport_from
and r1.airport_to <> r.airport_from
and REGEXP_INSTR('%'+r1.airport_to+'%', r.Route) = 0
)
select Route
from RoutesCTE
where airport_from = 'MVO'
and airport_to = 'NOV'
and TransfersCount <= 2;

MySQL Group By - Three tables with MIN function

I have searched on here to find an answer to my problem but to no avail.
I am working on a project where there are 3 tables involved, the 3 tables are flights, accommodation, and transfers.
The task is to find the cheapest price per month and per day so two separate queries.
The first query is to find the min price per month, an example:
SELECT
sub_a.startdate,
ROUND((
MIN(sub_a.aprice) +
MIN(sub_f.fprice) +
(SELECT MIN(t.PricePP) FROM matrix.iv_transfers AS t WHERE t.PropertyID = sub_a.PropertyID AND t.Adults = sub_a.adults AND t.Airport = sub_f.arrairport AND (sub_a.startdate BETWEEN t.RangeStart AND t.RangeEnd)) +
2.50
)) AS TotalPP,
ROUND(
(
MIN(sub_a.aprice) +
MIN(sub_f.fprice) +
(SELECT MIN(t.PricePP) FROM matrix.iv_transfers AS t WHERE t.PropertyID = sub_a.PropertyID AND t.Adults = sub_a.adults AND t.Airport = sub_f.arrairport AND (sub_a.startdate BETWEEN t.RangeStart AND t.RangeEnd)) +
2.50
) * 1.1
) AS TotalAgtPP,
sub_f.depairport,
sub_f.arrairport,
MONTH(sub_a.startdate) AS startdatet,
DATE_FORMAT(sub_a.startdate, "%b %y") AS FormatDate,
sub_a.duration,
sub_a.PropertyID
FROM (
SELECT
a.aid,
f.fid,
a.startdate,
f.outbounddate,
MIN(a.aprice) AS aprice,
MIN(f.fprice) AS fprice
FROM matrix.iv_liveaccomm AS a
JOIN matrix.iv_liveflights AS f USING (location, duration, adults)
WHERE a.PropertyID = 22
AND a.duration = 7
AND a.adults = 2
AND a.board = 'BB'
AND f.outbounddate = a.startdate
AND f.depairport = 'LHR'
GROUP BY a.aid, f.fid, a.startdate, f.outbounddate
) AS X
JOIN matrix.iv_liveaccomm AS sub_a ON(sub_a.aid = X.aid)
JOIN matrix.iv_liveflights AS sub_f ON(sub_f.fid = X.fid)
GROUP BY MONTH(X.startdate);
The query above returns the following result:
The 2nd query is to retrieve the min price per day for a given month.
SELECT
MONTH(sub_a.startdate) AS month_date,
ROUND((
sub_a.aprice +
sub_f.fprice +
(SELECT MIN(t.PricePP) FROM matrix.iv_transfers AS t WHERE t.PropertyID = sub_a.PropertyID AND t.Adults = sub_a.adults AND t.Airport = sub_f.arrairport AND (sub_a.startdate BETWEEN t.RangeStart AND t.RangeEnd)) +
2.50
)) AS TotalPP,
sub_f.depairport,
sub_f.arrairport,
MONTH(sub_a.startdate) AS startdatet,
DATE_FORMAT(sub_a.startdate, "%b %y") AS FormatDate,
sub_a.duration,
sub_a.PropertyID,
h.iv_PropertyReferenceID AS PropertyReferenceID,
sub_a.board,
sub_a.room,
sub_a.rating,
sub_a.`2for1`,
sub_a.`3for2`,
sub_a.`4for3`,
sub_a.`3and4`,
sub_a.freebb,
sub_a.adults,
sub_a.children,
sub_a.nss,
CONCAT("/search/results?tkn=",DATE_FORMAT(sub_a.startdate,"%d-%m-%Y"),"|",sub_a.duration,"|","A:",da.iv_AirportID,"|A:",aa.iv_AirportID,",R:",des.iv_RegionID,"|",r.iv_ResortID,"|",h.iv_PropertyReferenceID,"|",m.iv_MealBasisID,"|",sub_a.rating,"|1|",sub_a.adults,sub_a.children,",0|0,0,0|0,0,0|LPP|",sub_a.PropertyID) AS DeepLink
FROM (
SELECT
a.aid,
f.fid,
a.startdate,
f.outbounddate,
MIN(a.aprice) AS aprice,
MIN(f.fprice) AS fprice
FROM matrix.iv_liveaccomm AS a
JOIN matrix.iv_liveflights AS f USING (location, duration, adults)
WHERE a.PropertyID = 22
AND a.duration = 7
AND a.startdatet = 6
AND a.adults = 2
AND a.board = 'BB'
AND f.outbounddate = a.startdate
AND f.depairport = 'LHR'
GROUP BY a.aid, f.fid, a.startdate, f.outbounddate
) AS X
JOIN matrix.iv_liveaccomm AS sub_a ON(sub_a.aid = X.aid)
JOIN matrix.iv_liveflights AS sub_f ON(sub_f.fid = X.fid)
JOIN global.hotels AS h ON(h.iv_PropertyID = sub_a.PropertyID)
JOIN global.resorts AS r ON (r.iv_ResortID=h.iv_ResortID)
JOIN global.destinations AS des ON (des.iv_RegionID=r.iv_RegionID)
JOIN global.airports AS da ON (da.airportcode=sub_f.depairport)
JOIN global.mealbasis AS m ON (m.MealBasisCode=sub_a.board)
JOIN global.airports AS aa ON (aa.airportcode=sub_f.arrairport)
GROUP BY X.startdate;
and produces the following result:
As you can see from the first screenshot, the minimum price in June is 383 but in the 2nd screenshot, the minimum price is 386.
Why is the price different from grouping by month and date?
Thanks

How to sort before using STUFF in SSRS

I have 2 different values I'm trying to STUFF here. It is Quantity + Price. For example: 1-$0.36; 100-$0.29; 25-$0.31. How can I have it sort by Quantity before being stuffed? (1,25,100 instead of 1,100,25) I did come across this link Sort data before concatenating using STUFF FOR XML, but it dealt with 1 value and I'm dealing with 2 values
SELECT STUFF(
(SELECT DISTINCT TOP (5)
'; ' + (CAST(FLOOR(CASE WHEN PCFBD.Quantity IS NOT NULL THEN PCFBD.Quantity ELSE 1 END) AS VARCHAR) + '-$' + CAST(REPLACE(REPLACE(RTRIM(REPLACE(
CASE WHEN PCF.PriceMethod = 0 THEN ROUND(I.CdCost / (100 - PCF.FormulaPercent) * 100, 2)
WHEN PCFBH.PriceFormula = 2 AND PCFBD.FormulaPercent IS NULL THEN ROUND(I.CdCost / (100 - PCF.FormulaPercent) * 100, 2)
WHEN PCFBH.PriceFormula = 2 AND PCFBD.FormulaPercent IS NOT NULL THEN ROUND(I.CdCost / (100 - PCFBD.FormulaPercent) * 100, 2)
WHEN PCFBH.PriceFormula = 1 THEN ROUND((I.ListPrice * (100 - PCFBD.FormulaPercent)) * .01,2)
ELSE NULL END, '000' ,'')), ' ','0') + '', '. ', '') AS VARCHAR))
FROM Item AS I
INNER JOIN PriceContractFamily AS PCF ON I.FamilyId = PCF.FamilyId
AND I.ItemStatus IN (0, 5)
INNER JOIN StockItem SI ON I.ItemId = SI.ItemId
AND SI.WarehouseId = '502E5876-C26B-4E11-8B88-AFE0C34ECF0D'
LEFT OUTER JOIN PriceContractFamilyBracketHeader AS PCFBH ON PCF.PriceContractFamilyId = PCFBH.PriceContractFamilyId
LEFT OUTER JOIN PriceContractFamilyBracketDetail AS PCFBD ON PCFBH.BracketHeaderId = PCFBD.BracketHeaderId
WHERE I.ListPrice = #ListPrice
AND LEFT(I.ItemNumber, 6) = #ItemNumber
AND PCF.PriceContractId = #PriceContractId
FOR XML PATH('')),1, 2, '') AS QtyPrice
You should be able to add an ORDER BY before the FOR XML PATH statement.

SUM selected columns using alias and group by

I'm trying to perform calculations on select columns using aliases and a grouping by. Query is below(problem on line before the from):
select r.res_id,
r.arrive_date,
r.depart_date,
r.res_type,
if(DATEDIFF(r.depart_date, r.arrive_date) >29, 'LT', 'ST') as 'StayType',
SUM(r.rent + r.fee_arr_early + r.fee_dep_late + r.fee_peace_waiver + r.fee_pool + r.city_tax + r.fee_cleaning + r.fee_pet + r.fee_tshirt + r.fee_misc + r.fee_non_tax + r.fee_processing + r.fee_travel_ins + r.fee_event + r.fee_cancel) as 'folioTotal',
coalesce((select SUM(g.amount) from guest_payments as g where g.resId = r.res_id and charge_type = 'charge' and approved = 'Y'),0) as 'payments',
coalesce((select SUM(g.amount) from guest_payments as g where g.resId = r.res_id and charge_type = 'credit' and approved = 'Y'),0) as 'credits',
(SUM('folioTotal') - SUM('payments') + SUM('credits')) as 'folioBalance'
from reservations as r
join guest_payments as g
on r.res_id = g.resId
group by r.res_id
I've tried putting this inside another sum with the same outcome.
I was being stupid, I was referencing the aliases inside single ticks which is why it wasn't calculating. Solution:
select r.res_id,
r.arrive_date,
r.depart_date,
r.res_type,
g.entry_date,
if(DATEDIFF(r.depart_date, r.arrive_date) >29, 'LT', 'ST') as 'StayType',
(select SUM(r.rent + r.fee_arr_early + r.fee_dep_late + r.fee_peace_waiver + r.fee_pool + r.city_tax + r.fee_cleaning + r.fee_pet + r.fee_tshirt + r.fee_misc + r.fee_non_tax + r.fee_processing + r.fee_travel_ins + r.fee_event + r.fee_cancel) from reservations as r where r.res_id = g.resId) as 'folioTotal',
coalesce((select SUM(g.amount) from guest_payments as g where g.resId = r.res_id and charge_type = 'charge' ),0) as 'payments',
coalesce((select SUM(g.amount)* -1 from guest_payments as g where g.resId = r.res_id and charge_type = 'credit' and approved = 'Y'),0) as 'credits',
(select folioTotal - payments + credits)
from reservations as r
join guest_payments as g
on r.res_id = g.resId
group by r.res_id

SSRS Subscriptions - How to view ALL report recipients

I've written an SSRS report to help me keep track of SSRS subscriptions. I've repurposed a script that will use Reportserver.dbo.Subscriptions.LastStatus to view email recipients, however, it will only list the first 520 characters of LastStatus. Because some of our distribution lists are quite large, some of the names that my script searches for are not being found (even though they are part of the distribution). Below is the script that I am using:
SELECT Reportname = c.Name
,FileLocation = c.Path
,SubscriptionDesc=su.Description
,Subscriptiontype=su.EventType
,su.LastStatus
,su.LastRunTime
,Schedulename=sch.Name
,ScheduleType = sch.EventType
,ScheduleFrequency =
CASE sch.RecurrenceType
WHEN 1 THEN 'Once'
WHEN 2 THEN 'Hourly'
WHEN 4 THEN 'Daily/Weekly'
WHEN 5 THEN 'Monthly'
END
,su.Parameters
FROM Reportserver.dbo.Subscriptions su
JOIN Reportserver.dbo.Catalog c
ON su.Report_OID = c.ItemID
JOIN Reportserver.dbo.ReportSchedule rsc
ON rsc.ReportID = c.ItemID
AND rsc.SubscriptionID = su.SubscriptionID
JOIN Reportserver.dbo.Schedule Sch
ON rsc.ScheduleID = sch.ScheduleID
WHERE LastStatus like #Email
ORDER BY LastRunTime DESC
Any code that I have found online uses the LastStatus column to display this data. If anyone has any suggestions as to a more complete way for me to list all of the members of the report distribution list, I would appreciate it.
Below is SQL to query for the full text of the subscription parameters. I think this will work with extremely long address lists, but I don't have a test server with long address lists available right now.
If using this in production, I'd probably throw in a couple of WITH ( NOLOCK )'s and wouldn't expect support from MS on problems.
;
WITH subscriptionXmL
AS (
SELECT
SubscriptionID ,
OwnerID ,
Report_OID ,
Locale ,
InactiveFlags ,
ExtensionSettings ,
CONVERT(XML, ExtensionSettings) AS ExtensionSettingsXML ,
ModifiedByID ,
ModifiedDate ,
Description ,
LastStatus ,
EventType ,
MatchData ,
LastRunTime ,
Parameters ,
DeliveryExtension ,
Version
FROM
ReportServer.dbo.Subscriptions
),
-- Get the settings as pairs
SettingsCTE
AS (
SELECT
SubscriptionID ,
ExtensionSettings ,
-- include other fields if you need them.
ISNULL(Settings.value('(./*:Name/text())[1]', 'nvarchar(1024)'),
'Value') AS SettingName ,
Settings.value('(./*:Value/text())[1]', 'nvarchar(max)') AS SettingValue
FROM
subscriptionXmL
CROSS APPLY subscriptionXmL.ExtensionSettingsXML.nodes('//*:ParameterValue') Queries ( Settings )
)
SELECT
*
FROM
SettingsCTE
WHERE
settingName IN ( 'TO', 'CC', 'BCC' )
I also found this query from SQL Server MSDN Social;
Original Query Author MSDN Profile: Sandip Shinde
SELECT
c.Name AS ReportName,
'Next Run Date' = CASE next_run_date
WHEN 0 THEN null
ELSE
substring(convert(varchar(15),next_run_date),1,4) + '/' +
substring(convert(varchar(15),next_run_date),5,2) + '/' +
substring(convert(varchar(15),next_run_date),7,2)
END,
'Next Run Time' = isnull(CASE len(next_run_time)
WHEN 3 THEN cast('00:0'
+ Left(right(next_run_time,3),1)
+':' + right(next_run_time,2) as char (8))
WHEN 4 THEN cast('00:'
+ Left(right(next_run_time,4),2)
+':' + right(next_run_time,2) as char (8))
WHEN 5 THEN cast('0' + Left(right(next_run_time,5),1)
+':' + Left(right(next_run_time,4),2)
+':' + right(next_run_time,2) as char (8))
WHEN 6 THEN cast(Left(right(next_run_time,6),2)
+':' + Left(right(next_run_time,4),2)
+':' + right(next_run_time,2) as char (8))
END,'NA'),
Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="TO"])[1]','nvarchar(50)') as [To]
,Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="CC"])[1]','nvarchar(50)') as [CC]
,Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="RenderFormat"])[1]','nvarchar(50)') as [Render Format]
,Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="Subject"])[1]','nvarchar(50)') as [Subject]
---Example report parameters: StartDateMacro, EndDateMacro & Currency.
,Convert(XML,[Parameters]).value('(//ParameterValue/Value[../Name="StartDateMacro"])[1]','nvarchar(50)') as [Start Date]
,Convert(XML,[Parameters]).value('(//ParameterValue/Value[../Name="EndDateMacro"])[1]','nvarchar(50)') as [End Date]
,Convert(XML,[Parameters]).value('(//ParameterValue/Value[../Name="Currency"])[1]','nvarchar(50)') as [Currency]
,[LastStatus]
,[EventType]
,[LastRunTime]
,[DeliveryExtension]
,[Version]
FROM
dbo.[Catalog] c
INNER JOIN dbo.[Subscriptions] S ON c.ItemID = S.Report_OID
INNER JOIN dbo.ReportSchedule R ON S.SubscriptionID = R.SubscriptionID
INNER JOIN msdb.dbo.sysjobs J ON Convert(nvarchar(128),R.ScheduleID) = J.name
INNER JOIN msdb.dbo.sysjobschedules JS ON J.job_id = JS.job_id
According to MS (https://learn.microsoft.com/en-us/sql/reporting-services/subscriptions/manage-subscription-owners-and-run-subscription-powershell?view=sql-server-ver16), you can also use this powershell command:
$webSRV = New-WebServiceProxy -Uri "http://myservername/ReportServer/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential;
$mySubsList = $webSRV.ListSubscriptions("/");
$mySubsList | select *