SlideShare a Scribd company logo
1 of 124
1 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
PROCEDURE FOR MONTH-END
DAYS 2 (AM & PM) & 3 (AM)
NOTE: MANY OF THE SCREEN SHOTS ARE FOR INFORMATIONAL PURPOSES ONLY—THEY MAY NOT
MATCH THE DATA IN A PREVIOUS SCREEN SHOT.
DAY 2 (AM)
Step 1: You will receive anupdated Excel file fromJeanaLackey [see steps 5(g) and5(g)(1) fromDay1].
BUSINESS_UNIT
Correct
BU NAME1 ACCOUNT
Correct
Account DEPTID
Correct
Dept
65512 65525 WKGR-FM-WestPalmBeach,FL 493000 0
67111 65525 WZZR-FM-WestPalmBeach,FL 493000 0
26123 KOA-AM-Denver,CO 500000 0 110
53111 53115 WFBQ-FM-Indianapolis,IN 560800 731
64121 64127 WGST-AM-Atlanta,GA 560800 731
65321 65337 WBTP-FM-Tampa,FL 560800 731
65611 65619 WMGF-FM-Orlando,FL 560800 731
67211 67217 WBVD-FM-Melbourne,FL 560800 731
71123 71127 WKKF-FM-Albany,NY 560800 731
71511 71526 WKGS-FM-Rochester,NY 561300 113
15737 15737 SharedServ-SanFrancisco,CA 820000 0 731
Step 1(a): Run the MBR COMBO EDITS-SECONDPASS-REPORTEDTOACCOUNTINGscript.
Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth
End ProceduresSQLScriptsDay2MBRCOMBO EDITS-SECONDPASS-REPORTEDTOACCOUNTING(Run
DuringMBR Cash Month EndCycle) (6).sql
ServerName: pssqlclusfnprod
Database: FNPROD
Authentication: SQL ServerAuthentication
Log In: sqldev
Password: whatareyoudoing??
Step 1(a)(1):You will needtorunthe following --SELECT count (*) Statement dependingon
whetherthe correctionisa BusinessUnit(BU),Accountor Department ID.
The SET BUSINESS_UNIT, SET ACCOUNTandSET DEPTID numberis the correct number.
The WHERE BUSINESS_UNIT,AND ACCOUNT,ANDDEPTID number will be the incorrect BusinessUnit,
Accountor DepartmentID.
2 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Make sure to enterthe current valuesbefore proceedingand run each script independentlybasedon
the correctionthat needsto be done.
STOP: DO NOT INCLUDE THE UPDATE AS PART OF RUNNING THE SCRIPT; HOWEVER, YOUMUST
CORRECT THE SET BUSINESSUNIT IN THE UPDATE SCRIPT AS PART OFTHE NEXT STEP.
--Business Unit Update
UPDATE PS_CCW_JRNL_LN
SET BUSINESS_UNIT = '71526'
----SELECT count (*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '71511'
AND ACCOUNT = '561300'
AND DEPTID = '113'
----ROWS = 1
--Account Update
UPDATE PS_CCW_JRNL_LN
SET ACCOUNT = '214100'
---- SELECT count(*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '36320'
AND ACCOUNT = '214000'
AND DEPTID = '000'
AND APPL_JRNL_ID='MBR_AUTO'
----ROWS = 1
3 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
--Department Update
UPDATE PS_CCW_JRNL_LN
SET DEPTID='731'
----SELECT count (*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '15737'
AND ACCOUNT = '820000'
AND DEPTID = '000'
----ROWS = 1
Dependingonwhichscriptwasused,one of the followingresultswillappear. These are examplesonly,
the resultswill normallyreturn1.
BusinessUnitUpdate
Account Update
4 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Department Update
Step 1(a)(2): Once youhave correctedthe UPDATE scriptand ----SELECT count (*) statement,
run the entire scripttoupdate the BU, Accountand DeptID. Make sure to run each script
independentlybasedonthe correctionthatneedstobe made.
--Business Unit Update
UPDATE PS_CCW_JRNL_LN
SET BUSINESS_UNIT = '71526'
----SELECT count (*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '71511'
AND ACCOUNT = '561300'
AND DEPTID = '113'
----ROWS = 1
--Account Update
UPDATE PS_CCW_JRNL_LN
SET ACCOUNT = '214100'
---- SELECT count(*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '36320'
AND ACCOUNT = '214000'
AND DEPTID = '000'
AND APPL_JRNL_ID='MBR_AUTO'
----ROWS = 1
5 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
--Department Update
UPDATE PS_CCW_JRNL_LN
SET DEPTID='731'
----SELECT count (*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '15737'
AND ACCOUNT = '820000'
AND DEPTID = '000'
----ROWS = 1
Dependingonwhichscriptwasused,one of the followingresultswillappear. These are examplesonly.
BusinessUnitUpdate
Account Update
6 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Department Update
Step 1(b): To ensure thatyouhave correctedall the BU’s, Account andDepartmentID runthe following
script. Make sure to change the date.
/*********** SQL TO DETERMINE FAILED COMBO EDITS (AFTER INITIAL COMBO EDIT
SCRUBBING)***********************/
SELECT DISTINCT J.BUSINESS_UNIT,M.NAME1, J.ACCOUNT, J.DEPTID, LINE_DESCR,
FOREIGN_AMOUNT, JOURNAL_DATE
FROM PS_CCW_JRNL_LN as J WITH (NOLOCK)
JOIN PS_CCW_JRNL_HDR AS H WITH (NOLOCK)
ON H.CCW_JRNL_SRC_ID = J.CCW_JRNL_SRC_ID
LEFT OUTER JOIN /*FNPROD_READER.FNPROD.*/dbo.PS_CCW_DEPT_CE_VW AS
C --WITH (NOLOCK) Combo Edit View
ON J.BUSINESS_UNIT = C.BUSINESS_UNIT
AND J.ACCOUNT = C.ACCOUNT
AND J.DEPTID = C.DEPTID
JOIN PS_CCW_MBR_STATION AS M WITH (NOLOCK)
ON M.BUSINESS_UNIT = J.BUSINESS_UNIT
WHERE JOURNAL_DATE BETWEEN '08/1/11' AND '08/31/11'
AND C.BUSINESS_UNIT IS NULL
AND J.APPL_JRNL_ID='MBR_AUTO'
--AND J.ACCOUNT NOT IN
('420750','420760','214100','214300','214500','551200','560005','560000','550
000','560800','800000','810200','822000','822000','810000','561300','561400',
'561500')
--AND J.DEPTID <> '0'
ORDER BY J.ACCOUNT, J.BUSINESS_UNIT
7 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
The resultshouldcome backblank. If not,thenyouhave made an erroror you may nothave captured
all the corrections. Go back to the excel file andre-runthe corrections.
Step 2: Runthe ----SELECT * Statementportionof the Update Statementof ImportStatusscript.
Thisis the same numberof failedJournal Entries (‘F”) returnedinthe PeopleSoft reportof Step6(c) of
Day 1.
STOP: DO NOT INCLUDE THE UPDATE AS PART OF RUNNING THE SCRIPT.
/************************ UPDATE STATEMENT FOR IMPORT STATUS
******************************/
UPDATE PS_CCW_JRNL_HDR
SET CCW_IMPORT_STATUS = 'R'
----SELECT * FROM PS_CCW_JRNL_HDR
WHERE CCW_IMPORT_STATUS = 'F'
----ROWS = 12
8 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
The followingresultwillappear.
Step 2(a): Run the UPDATE scriptto verifyyourrow counts. Thischangesthe “F” to “R”.
F = Failed
R = Ready
/************************ UPDATE STATEMENT FOR IMPORT STATUS
******************************/
UPDATE PS_CCW_JRNL_HDR
SET CCW_IMPORT_STATUS = 'R'
----SELECT * FROM PS_CCW_JRNL_HDR
WHERE CCW_IMPORT_STATUS = 'F'
----ROWS = 12
The followingresultwillappear. If the row countsdo not match the row countsinyour updated row
countsfrom the scriptabove,youhave made an error.
9 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 3: Email or walkoverto DavidDe La Fuente andlethimknow that he can run the importjournal.
If David runsthe importjournal and discoversafailedjournal,proceedtostep3(b). Youcan check the
statusof the processinPeopleSoftbyviewingthe ProcessMonitor.
Link to PeopleSoft:
https://fnprod.mssql.peoplesoft.clearchannel.com/psp/ps/EMPLOYEE/PSFT_EP/?cmd=logout
UserID: JE_SYSTEM_USER
Password: Meatloaf
10 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 3(a): Run the followingbabysit scriptforImportJournals. Youwill see the numberof successful
and readyjournals(these are the onesyourcorrectedinstep1). The numberof “R” importsshould
equal the numberof rowcounts that appearsinthe screenshotfor steps2 and 2(a).
You cannot proceedto the next stepuntil this is done.
S= Success
R=Ready
/************************ BABYSIT STATEMENT FOR IMPORTJOURNALS PS JOB
******************************/
--Run this journal to babysit IMPORTJOURNALS PS Job
select CCW_IMPORT_STATUS, COUNT(*)
from PS_CCW_JRNL_HDR WITH (NOLOCK)
WHERE APPL_JRNL_ID='MBR_AUTO'
GROUP BY CCW_IMPORT_STATUS
11 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 3(b): To findthe failedjournal,runthe followingscript. Thisisdone on an exceptionbasis.Make
sure to run both scripts at the same time. If you needassistance for this process,contact Kushan
Edussuriya or David De La Fuente.Make a note of the BU listedunderBUSINESS_UNIT,Invoice number
listedunderLINE_DESCR.
/********************* FAILED JOURNAL *********************************/
--Run this to find any failed journals
select *
from PS_CCW_JRNL_HDR WITH (NOLOCK)
WHERE APPL_JRNL_ID='MBR_AUTO'
and CCW_IMPORT_STATUS='F'
select *
from PS_CCW_JRNL_LN
WHERE APPL_JRNL_ID='MBR_AUTO'
AND CCW_JRNL_SRC_ID='3589'
The script will returnthe followingresult.
12 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 3(b)(1): Go to AXto lookat the BU to see whatit contains.AXGeneralLedgerDimensions>
Change Dimensionto Station>insertBU. You will notice the BUdoesexistinAXbutfor some reason
doesnotexistinPeopleSoft.
Step 3(b)(2): Go toPeopleSofttolocate the businessUnit. PeopleSoftSetUpFinancials/Supply
ChainBusinessUnitRelatedGeneral LedgerGeneral LedgerDefinitionEnterthe BU and see what
resultyouget. Normally,youwill see thatPeopleSoftdoesnothave the BU.
Linkto PeopleSoft:
https://fnprod.mssql.peoplesoft.clearchannel.com/psp/ps/EMPLOYEE/PSFT_EP/?cmd=logout
UserID: JE_SYSTEM_USER
Password: Meatloaf
13 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 3(b)(3): To correctthe problem,youwill needtoreviewthe Journal andInvoice. Tofindthe
Journal go to AXGeneral LedgerReportsPostedtransactionsbyjournalClickSelectChangeFieldto
VoucherandCriteriato the invoice number. Itwill returnaJournal Voucher.
Step 3(b)(4): Insertthe Vouchernumberintothe criteriafield. Youcan obtainthat numberfromstep
3(b).ClickOkay.
14 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
ClickOkayon the PostedtransactionbyJournal – Reportscreenand hitokayonce againon the Posted
by Journal screen. The followingscreenwill appear. Make a note of the JV number.
Step 3(b)(4): You will thenneedtoreview the lines forthe Journal bygoingtoAXAccounts
ReceivablesPaymentJournalInsertJV number>SelectLines
15 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 3(b)(5): Locate the SharedServicesBU forthissite by goingto AXGeneral
LedgerDimensionsStation>InsertSite #.
Step 3(b)(6): Run the----SELECT count (*) Statementtoget the row count and update the BU
(see step1 on where toenterfailedandcorrectBU):
--Business Unit Update
UPDATE PS_CCW_JRNL_LN
SET BUSINESS_UNIT = '52222'
----SELECT count (*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '55211'
AND ACCOUNT = '560005'
AND DEPTID = '598'
----ROWS = 1
Step 3(b)(7): Run the UPDATE script.
--Business Unit Update
UPDATE PS_CCW_JRNL_LN
SET BUSINESS_UNIT = '52222'
----SELECT count (*) FROM PS_CCW_JRNL_LN
WHERE BUSINESS_UNIT = '55211'
AND ACCOUNT = '560005'
AND DEPTID = '598'
----ROWS = 1
Step 3(b)(8): Run the ImportJournal Script referencedinstep3(a) until yousee “S.”
************************ BABYSIT STATEMENT FOR IMPORTJOURNALS PS JOB
******************************/
--Run this journal to babysit IMPORTJOURNALS PS Job
select CCW_IMPORT_STATUS, COUNT(*)
from PS_CCW_JRNL_HDR WITH (NOLOCK)
WHERE APPL_JRNL_ID='MBR_AUTO'
GROUP BY CCW_IMPORT_STATUS
16 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Example of Successful ImportJournal
S = Success
Step 4: Runthe MBR ExceptionQueriesScript. Make sure to change the journal date and transdate.
Note: This step is notdependent on the prior step.
Look for NULL (couldbe in BU or other columns – a.k.ain SQL Script as CCARSite).
Linkto obtainscript: CCIFS1SATCommonFinancialInfoSystems&ReportingAX
QueriesMonthendMonthEndProceduresSQLScriptsDay2MBRExceptionQueries(4).sql
Server: AXSQLCluster
Database: AX Reporting
Authentication: WindowsAuthentication
17 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
--MBR Exception Queries
select distinct mbrex.ProcessID, mbrex.DataFlowDesc,
mbrex.TransformationDesc,
mbrex.CCARSite, mbrex.AccountNum, mbrex.VoucherNum, mbrex.BusinessUnit
'08/31/2011' AS 'Journal Date', mbrex.DeptID, mbrex.ForeignAmount,
jrnlsub.JOURNALNUM, jrnlsub.JOURNALNUM+'-'+jrnlsub.VOUCHER as 'LineDesc',
ErrorDesc
from MBREXCEPTIONS mbrex (nolock),
(select distinct LJT.VOUCHER, LJT.JOURNALNUM
from AXLEDGERJOURNALTRANS ljt (nolock)
where TRANSDATE between '20110801' and '20110831'
)
as jrnlsub
WHERE mbrex.IsError=1
AND mbrex.VoucherNum NOT LIKE 'INV%'
and jrnlsub.voucher=mbrex.VoucherNum
order by mbrex.VoucherNum
select *
from MBREXCEPTIONS (nolock)
where VoucherNum not like 'INV%'
order by VoucherNum
The followingresultswill be returned.
Step 4(a): Copyand paste the data only (donot copy the headers) fromthe SQLscript andput intothe
excel file underthe tab,“RawFile.” The template forthisexcel file canbe foundbygoingto
ccifs1satcommonFinancialInfoSystems&ReportingAXQueriesMonthendMonthEnd
ProceduresTemplate Documents2011MBR JET Cash ExceptionTemplate(rev080511).xlsx
The Excel file contains formulasand pre-populatedinformationinthe tab marked “JET”,so do not
make any changes to those cells.
18 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
In the scriptabove,youwill receive severalNULL’sforthe BU. FilteroutanyBU that isNULL. You must
populate those NULL’s.
Step 4(b): Locate the SharedServicesBUfor the NULL BU’s bygoingto AX>General
Ledger>Dimensions>Station>Site>InsertSite forBU that isNULL. Enterthe BU numberforthe Shared
Servicesintothe excel file underthe tablabeled,“Raw File.”
19 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Make sure to un-filterandun-highlightthe databefore sendingittoAR.
Step 4(c): Go to the excel tablabeled,“JET”and note the following:
 Change the AccountingDate (ColumnA) inthe M/DD/YY format andmake sure to carry itall the
waydown. For example,forthe August close,we usedadate of 8/01/11.
 KeepProjectID- Chartfield1(ColumnF),andOper.Unit(ColumnI) blank.
 BusinessUnitLine (ColumnB),Account(ColumnC), Amount(ColumnE),andLine Description
(ColumnH) containformulas,whichwill autopopulate.
 DepartmentID(ColumnD),Jrnl Line Ref (ColumnG) andCurrencyCD (ColumnJ) containpre-
populatedinformation. DONOT INSERT ANYTHING INTO THESE COLUMNS.
Make sure to save thisfile usingthe followingpath: NetworkCCIFS1SATCommonFinancial Info
Systems&ReportingAXQueriesMonthendMonthEndProcedures>(lookforfolderwiththe
correspondingmonthyouare closingi.e. “September2011 Close Document”forAugustclose). Make
sure to convert thisinto a “text” filebefore saving.
20 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 4(d): Sendthe file toJeanaLackey and copySylviaFowler(Director –FIS).
Day 2 (PM) – Day 3 (AM)
Step 5: Run RadioDM Queries(Invoice Tie Out-DailyLoads-Summaryof Sites-IncludingBill Payer).sql.
Make sure to change the dates (locatedin two area’s inthe script).
Make sure to run entire script.
YOUCAN NOT PROCEED UNTIL YOUHAVE HEARD FROM SYLVIAFOWLER. WE ARE WAITING FORTHE
CALANDER INVOICELOAD FROM RADIO DM TO AX.
Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth
End ProceduresSQLScriptsDay2RadioDMQueries(Invoice Tie Out-DailyLoads-Summaryof Sites-
IncludingBill Payer) (3).sql
Server: dwsqlclu8sql101
Database: Radio DM
Authentication: SQL ServerAuthentication
Log In: sqldev
Password: whatareyoudoing??
21 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
declare @InvoiceMonth datetime
declare @InvDateTo datetime
set @InvoiceMonth='2011-08-01'
set @InvDateTo='2011-08-31'
--Daily Load Tie Out Query Detail (Radio DM) with Sales Tax Included-Summary
--Make one query for each site with Sales Tax
SELECT QRY3.SITEID, QRY3.SITENAME, SUM(QRY3.DMAMT) FROM (
--Site 44 Honolulu HI
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) AS 'DMAMT'
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '44'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
22 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '44'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '44'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '44'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '44'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
UNION ALL
23 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
--Site 51 Phoenix AZ
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '51'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '51'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '51'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '51'
and ih.InvoiceRowType=1
and ir.Autofill=0
24 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '51'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
UNION ALL
--Site 68 Sarasota FL
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '68'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
25 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '68'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '68'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '68'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '68'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
26 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
group by qry2.SiteID, st.SiteName
UNION ALL
--Site 81 Orlando FL
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '81'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '81'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '81'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
27 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
where ih.SiteID = '81'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '81'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
UNION ALL
--Site 110 Albuquerque NM
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '110'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
28 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '110'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '110'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '110'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '110'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
29 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
UNION ALL
--Site 268 Farmington NM
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '268'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '268'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '268'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
30 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '268'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '268'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
UNION ALL
--Site 294 Gallup NM
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '294'
and ih.InvoiceRowType=1
and ir.Autofill=0
31 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '294'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '294'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '294'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '294'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
32 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
UNION ALL
--Site 306 Florida Keys FL
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '306'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '306'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '306'
and invoiceid in (
select qry1.invoiceid from
(
33 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '306'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '306'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
UNION ALL
--Site 312 West Palm Beach FL
SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt)
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
34 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '312'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '312'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION ALL
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '312'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '312'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '312'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
35 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.SiteID, st.SiteName
--End Daily Load Tie Out Query Detail (Radio DM) with Tax Included-Summary
UNION ALL
--Daily Load Tie Out Query Summary (Radio DM-Non Tax Sites)
select qry2.siteid, st.sitename, SUM(qry2.LineTot) from (
select qry1.siteid, SUM(qry1.LineAmt) as 'LineTot' from
(
select ir.SiteID, ih.Orderid, ir.invoiceID,
ir.EnterpriseRevenueTypeID,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID in ('43','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','45','47','49','56','60','62',
'74','75','80','82','86','87','88','90','100',
'102','118','120','122','134','151','155','157', '159',
'158','160','163','165','168','175','181','187','188','192',
'194','243','247','258','275','277','240','290'
)
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
36 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID,
ir.EnterpriseRevenueTypeID,
ir.grossrate, ir.AgencyCommissionPct
)
as qry1
group by qry1.SiteID
UNION ALL
--Misc Invoice Rows
select mrc.SiteID,
sum(mrc.InvNetRate)
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID in ('43','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','45','47','49','56','60','62',
'74','75','80','82','86','87','88','90','100',
'102','118','120','122','134','151','155','157', '159',
'158','160','163','165','168','175','181','187','188','192',
'194','243','247','258','275','277','240','290'
)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
group by mrc.SiteID
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
group by qry2.siteid, st.SiteName
UNION ALL
--Bill Payer Daily Load Tie Out Query Summary (Radio DM)
SELECT qry2.SiteID, st.SiteName,
SUM(qry2.DMAmt)/2
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
37 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as
LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID in (396,398,399,597)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
UNION ALL
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID in (396,398,399,597)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
where qry2.SiteID in ('43','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
'102','110','118','120','122','134','151','155','157',
'159',
'158','160','163','165','175','181','187','188','192',
38 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
'194','243','247','258','268','275','277','294','306',
'312',
'168','240','290'
)
group by qry2.SiteID, st.SiteName
UNION ALL
--Affiliate Queries Bill Payer (Summary) from Radio DM (Sacramento)
select qry2.siteid, st.SiteName, SUM(qry2.LineTot)/2 from
(
select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS
'LineTot' from
(
select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID, l.StationID,
sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as
LineAmt
from Viero.tInvoiceRow ir (nolock)
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID
and ir.SiteID = l.SiteID
where ih.SiteID in ('99')
and l.StationID not in (35,36,37,38,39,40)
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID in (396,398,399,597)
GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID,
ir.grossrate, ir.AgencyCommissionPct, l.StationID
)
as qry1
group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth
UNION ALL
select mrc.SiteID,
mrc.InvoiceNo, ih.InvoiceMonth,
sum(mrc.InvNetRate)
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID in ('99')
and mrc.StationID not in (35,36,37,38,39,40)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID in (396,398,399,597)
group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth
)
AS QRY2
join dbo.tSite st
on qry2.SiteID=st.SiteID
GROUP BY qry2.siteid, st.SiteName
39 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
UNION ALL
--Affiliate Queries Bill Payer (Summary) from Radio DM (Salt Lake City)
select qry2.siteid, st.SiteName, SUM(qry2.LineTot)/2 from
(
select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS
'LineTot' from
(
select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID, l.StationID,
sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as
LineAmt
from Viero.tInvoiceRow ir (nolock)
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID
and ir.SiteID = l.SiteID
where ih.SiteID in ('137')
and l.StationID not in (73)
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID in (396,398,399,597)
GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID,
ir.grossrate, ir.AgencyCommissionPct, l.StationID
)
as qry1
group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth
UNION ALL
select mrc.SiteID,
mrc.InvoiceNo, ih.InvoiceMonth,
sum(mrc.InvNetRate)
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID in ('137')
and mrc.StationID not in (73)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID in (396,398,399,597)
group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth
)
AS QRY2
join dbo.tSite st
on qry2.SiteID=st.SiteID
GROUP BY qry2.siteid, st.SiteName
UNION ALL
--Bill Payer Summary (Sacramento)
select qry2.siteid, st.sitename, sum(qry2.LineTot) from
(
40 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS
'LineTot' from
(
select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID, l.StationID,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID
and ir.SiteID = l.SiteID
where ih.SiteID in ('99')
and l.StationID not in (35,36,37,38,39,40)
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID,
ir.grossrate, ir.AgencyCommissionPct, l.StationID
)
as qry1
group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth
UNION ALL
select mrc.SiteID,
mrc.InvoiceNo, ih.InvoiceMonth,
sum(mrc.InvNetRate)
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID in ('99')
and mrc.StationID not in (35,36,37,38,39,40)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth
)
AS QRY2
join dbo.tSite st
on qry2.SiteID=st.SiteID
GROUP BY qry2.siteid, st.SiteName
UNION ALL
--Bill Payer Summary (Salt Lake City)
select qry2.siteid, st.sitename, sum(qry2.LineTot) from
(
select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS
'LineTot' from
(
select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID, l.StationID,
41 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID
and ir.SiteID = l.SiteID
where ih.SiteID in ('137')
and l.StationID not in (73)
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID,
ir.grossrate, ir.AgencyCommissionPct, l.StationID
)
as qry1
group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth
UNION ALL
select mrc.SiteID,
mrc.InvoiceNo, ih.InvoiceMonth,
sum(mrc.InvNetRate)
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID in ('137')
and mrc.StationID not in (73)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth
)
AS QRY2
join dbo.tSite st
on qry2.SiteID=st.SiteID
GROUP BY qry2.siteid, st.SiteName
)
AS QRY3
GROUP BY qry3.siteid, QRY3.SiteName
order by QRY3.siteid
-----------------------------------------------------------------------------
--------------------------
--Daily Load Tie Out Query Summary (DAX) with Sales Tax Included
select qry1.ccarsite, SUM(qry1.AXAmt) as 'AXSum' from
(
--Invoice Load (Excluding Trade)
select CCARSITE, INVOICEID, CCARSOURCEINVOICENO, SUM(INVOICEAMOUNT) as
'AXAmt'
from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTINVOICEJOUR] with (nolock)
WHERE CCARSITE in ('43','99','190','61','106', --Round 1
42 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152',Is th '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318', '137',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
'102','110','118','120','122','134','151','155','157',
'159',
'158','160','163','165','175','181','187','188','192',
'194','243','247','258','268','275','277','294','306','312',
'168','240','290'
)
--AND INVOICEDATE BETWEEN @InvoiceMonth AND @InvDateTo
AND INVOICEDATE BETWEEN '20110801' AND '20110831'
AND INVOICEID NOT LIKE 'CRD%'
and CCARINVOICEACTION='0'
GROUP BY CCARSITE, INVOICEID, CCARSOURCEINVOICENO
HAVING SUM(INVOICEAMOUNT) <> 0
UNION ALL
--Manual Invoices
select b.CCARSITE, A.VOUCHER, a.ccarsourceorderno,
SUM(amountcur) as 'AXAmt'
from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[ccarCUSTTRANSdetail] a with
(nolock)
join [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTTABLE] b with (nolock) on
a.accountnum = b.ACCOUNTNUM
--where TRANSDATE BETWEEN @InvoiceMonth AND @InvDateTo
where TRANSDATE BETWEEN '20120501' AND '20120531'
AND B.CCARSITE in ('43','99','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318', '137',
43 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
'102','110','118','120','122','134','151','155','157',
'159',
'158','160','163','165','175','181','187','188','192',
'194','243','247','258','268','275','277','294','306',
'312',
'168','240','290'
)
and a.dimension2_ <> '97000'
and (
(a.voucher BETWEEN 'MINV-000009925' AND 'MINV-000009994') or --Manual
Invoices (JV00180151)
(a.voucher BETWEEN 'MINV-000009995' AND 'MINV-000010044') --Correcting
Entries (JV00179906 and JV00180302)
)
Group by b.ccarsite, A.VOUCHER, a.ccarsourceorderno
)
as qry1
group by qry1.ccarsite
order by cast(qry1.ccarsite as int)
It will returnthe followingresult.
Step 5(a): Copyand Paste the data intothe excel sheettitled“Invoice Tie”inthe tab labeled,“Tie Out.”
The firsthalf of the scriptwill be pastedintocolumnsA – C andthe secondhalf of the scriptwill be
patedintocolumnsD – F. The useof column G will be explained later.
Make sure not to include the headers.
44 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
NOTE: MANY OFTHE FIELDS IN THE EXCEL DOCUMENT CONTAINSFORMULAS. THOSE CELLS ARE
PROTECTED.
Linkfor template document: CCIFS1SATCommonFinancial InfoSystems&ReportingAX
QueriesMonthendMonthEndProceduresTemplate DocumentsInvoice Tie OutTemplate.xlsx
Make sure to save a copy usingthe followingpath: NetworkCCIFS1SATCommonFinancial Info
Systems&ReportingAXQueriesMonthendMonthEndProcedures>(lookforfolderwiththe
correspondingmonthyouare closingi.e.“September2011 Close Document”forAugustclose).
Step 6: RunRadio DMQueries(Invoice Tie Out-DailyLoads-Summaryof Sites-Bill PayerInvoices).sql.
Make sure to change the dates. There are two locationsforthe date.
Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth
End ProceduresSQLScriptsDay2RadioDMQueries(Invoice Tie Out-DailyLoads-Summaryof Sites-Bill
PayerInvoices).sql
Server: dwsqlclu8sql101
Database: Radio DM
Authentication: SQL ServerAuthentication
Log In: sqldev
Password: whatareyoudoing??
45 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
declare @InvoiceMonth datetime
declare @InvDateTo datetime
set @InvoiceMonth='2011-08-01'
set @InvDateTo='2011-08-31'
--Daily Load Tie Out Query (Summary)
SELECT QRY3.SITEID, QRY3.SITENAME, SUM(QRY3.DMAMT) FROM (
--Bill Payer Daily Load Tie Out Query Summary (Radio DM)
SELECT qry2.SiteID, st.SiteName,
SUM(qry2.DMAmt)/2 as 'DMAmt'
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as
LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID in (396,398,399,597)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID in (396,398,399,597)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
as qry2
join dbo.tSite st
on qry2.SiteID=st.SiteID
where qry2.SiteID in ('43','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
46 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
'102','110','118','120','122','134','151','155','157',
'158','160','163','165','175','181','187','188','192',
'194','243','247','258','268','275','277','294','306',
'312',
'168','240','290'
)
group by qry2.SiteID, st.SiteName
UNION
--Bill Payer Summary (Sacramento)
select qry2.siteid, st.sitename, sum(qry2.LineTot)/2 from
(
select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS
'LineTot' from
(
select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID, l.StationID,
sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as
LineAmt
from Viero.tInvoiceRow ir (nolock)
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID
and ir.SiteID = l.SiteID
where ih.SiteID in ('99')
and l.StationID not in (35,36,37,38,39,40)
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID in (396,398,399,597)
GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID,
ir.grossrate, ir.AgencyCommissionPct, l.StationID
)
as qry1
group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth
UNION
select mrc.SiteID,
mrc.InvoiceNo, ih.InvoiceMonth,
sum(mrc.InvNetRate)
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID in ('99')
and mrc.StationID not in (35,36,37,38,39,40)
47 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID in (396,398,399,597)
group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth
)
AS QRY2
join dbo.tSite st
on qry2.SiteID=st.SiteID
GROUP BY qry2.siteid, st.SiteName
UNION
--Bill Payer Summary (Salt Lake City)
select qry2.siteid, st.sitename, sum(qry2.LineTot)/2 from
(
select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS
'LineTot' from
(
select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID, l.StationID,
sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as
LineAmt
from Viero.tInvoiceRow ir (nolock)
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID
and ir.SiteID = l.SiteID
where ih.SiteID in ('137')
and l.StationID not in (73)
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID in (396,398,399,597)
GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth,
ir.EnterpriseRevenueTypeID,
ir.grossrate, ir.AgencyCommissionPct, l.StationID
)
as qry1
group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth
UNION
select mrc.SiteID,
mrc.InvoiceNo, ih.InvoiceMonth,
sum(mrc.InvNetRate)
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID in ('137')
and mrc.StationID not in (73)
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID in (396,398,399,597)
group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth
)
AS QRY2
48 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
join dbo.tSite st
on qry2.SiteID=st.SiteID
GROUP BY qry2.siteid, st.SiteName
)
AS QRY3
GROUP BY qry3.siteid, QRY3.SiteName
order by QRY3.siteid
-----------------------------------------------------------------------------
--------------------------
--Daily Load Tie Out Query Summary (DAX) with Sales Tax Included
select qry1.ccarsite, SUM(qry1.AXAmt) as 'AXSum' from
(
--Bill Payer Invoices from VIERO (Excluding Sacramento)
select CIJ.CCARSITE, CIJ.INVOICEID,
CIJ.CCARSOURCEINVOICENO,
sum(cit.LINEAMOUNT) as 'AXAmt'
from [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICETRANS cit (nolock)
join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICEJOUR CIJ
(NOLOCK)
ON cit.INVOICEID=CIJ.INVOICEID
where cij.ccarsite in ('43','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318', '137',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
'102','110','118','120','122','134','151','155','157',
'158','160','163','165','175','181','187','188','192',
'194','243','247','258','268','275','277','294','306','312',
'168','240','290'
)
and cit.ITEMID in ('396','398','399','597')
and cit.INVOICEDATE between @InvoiceMonth and @InvDateTo
AND CIJ.CREATEDBY <> 'axtoo'
GROUP BY CIJ.CCARSITE, CIJ.INVOICEID,
CIJ.CCARSOURCEINVOICENO
union all
--Bill Payer Manual Invoices
select b.CCARSITE, A.VOUCHER, a.ccarsourceorderno,
SUM(amountcur) as 'AXAmt'
49 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[ccarCUSTTRANSdetail] a with
(nolock)
join [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTTABLE] b with (nolock) on
a.accountnum = b.ACCOUNTNUM
where TRANSDATE BETWEEN @InvoiceMonth AND @InvDateTo
AND B.CCARSITE in ('43','99','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318', '137',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
'102','110','118','120','122','134','151','155','157',
'158','160','163','165','175','181','187','188','192',
'194','243','247','258','268','275','277','294','306',
'312',
'168','240','290'
)
and a.dimension2_ <> '97000'
and (
(a.voucher BETWEEN 'MINV-000009845' AND 'MINV-000009846') or
(a.voucher BETWEEN 'MINV-000009847' AND 'MINV-000009882')
)
Group by b.ccarsite, A.VOUCHER, a.ccarsourceorderno
union all
--Bill Payer Invoices Sacramento
SELECT QRY1.CCARSITE, QRY1.VOUCHER, CIJ.CCARSOURCEINVOICENO,
SUM(QRY1.AXAMT) FROM
(
select b.CCARSITE, A.VOUCHER,
SUM(amountcur) as 'AXAmt'
from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[ccarCUSTTRANSdetail] a with
(nolock)
join [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTTABLE] b with (nolock) on
a.accountnum = b.ACCOUNTNUM
where TRANSDATE BETWEEN '20110801' and '20110831'
AND B.CCARSITE in ('99')
and a.dimension2_ <> '97000'
AND A.ITEMID in ('396','398','399','597')
group by b.CCARSITE, A.VOUCHER
)
AS QRY1
join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICEJOUR CIJ
(NOLOCK)
ON QRY1.VOUCHER=CIJ.INVOICEID
50 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
GROUP BY QRY1.CCARSITE, QRY1.VOUCHER, CIJ.CCARSOURCEINVOICENO
)
as qry1
group by qry1.ccarsite
order by cast(qry1.ccarsite as int)
Thiswill returnthe following results.
Step 6(a): Copyand Paste the data intothe excel sheettitled“Invoice Tie”inthe tab labeled,“Tie Out-
Bill Payer.” The firsthalf of the scriptwill be pastedintocolumnsA – C and the secondhalf of the script
will be patedintocolumnsD& E. Nocolumnname in SQL scriptis knownasRadioDMAmt(columnC)
and AXSum inSQL Script isknownas DAXAmount(columnE) inthe Excel file.
51 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Step 6(a)(1): Locate amountsin Tie Out-Bill Payerandcompare those toTie Outby Site. If the amounts
closelymatch(i.e.site 12“Tie – Out Bill Payer”$51.02 & site 12 “Tie Out” $51.05) thenright “Bill Payer”
underColumnG.
Step 7: Runthe RadioDM and DAX Queries(Package InvoicingIdentification).sql . Makesure to change
the dates. There are two locationsfordates towardsthe topof the script.
Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth
End ProceduresSQLScriptsDay2RadioDMand DAXQueries(Package InvoicingIdentification).sql
Server: dwsqlclu8sql101
Database: Radio DM
Authentication: SQL ServerAuthentication
Log In: sqldev
Password: whatareyoudoing??
52 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
DECLARE @INVDTFROM DATETIME
DECLARE @INVDTTO DATETIME
SET @INVDTFROM='20110801'
SET @INVDTTO='20110831'
-- This gives the list of Invoices associated with Package Charge Orders
(Post Migration).
Select qry2.siteid, qry2.stationid, qry2.INVID as 'VieroInv',
qry2.BillToCust, daxcust.accountnum as 'DAXBillTo',
qry2.AdvertiserID, daxadv.accountnum as 'DAXAdv',
qry2.InvoiceDate,
sum(qry2.NetRate) as 'InvoiceOutstanding'
from
(
Select TOC.SiteID,
TIHC.InvoiceID as 'INVID', 'BillToCust' =
case
when tihc.agencyid=0
then tihc.advertiserid
else TIHC.AgencyID
end,
tihc.advertiserid, DIM.NUM as 'StationID',
ir.GrossRate, ir.AgencyCommissionPct,
ir.GrossRate * (1 - ir.AgencyCommissionPct) as 'NetRate',
TIHC.InvoiceDate
from [RadioDM].[Viero].tOrder_Current TOC
Join [RadioDM].[Viero].tInvoiceHeader_Current TIHC
on TOC.SiteID = TIHC.SiteID
and TOC.OrderID = TIHC.OrderID
join [RadioDM].[Viero].tInvoiceRow IR
on TIHC.siteid=IR.Siteid
and TIHC.invoiceid=IR.invoiceid
join [RadioDM].[Viero].torderline_current OL
on IR.siteid=ol.siteid
and ir.orderlineid=ol.orderlineid
left join [RadioDM].[Viero].tStation sta
on ol.SiteID=sta.SiteID
and ol.stationid=sta.StationID
join [RadioDM].[ERSP].tStation cl
on sta.EnterpriseStationID=cl.EnterpriseStationID
left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[DIMENSIONS] DIM (NOLOCK)
on cl.Description COLLATE DATABASE_DEFAULT =
LEFT(DIM.DESCRIPTION,7) COLLATE DATABASE_DEFAULT
where TOC.PackageCharge = 1
and TIHC.InvoiceRowType = 1
UNION ALL
Select TOC.SiteID,
TIHC.InvoiceID as 'INVID', 'BillToCust' =
case
when tihc.agencyid=0
then tihc.advertiserid
else TIHC.AgencyID
end,
tihc.advertiserid, DIM.NUM as 'StationID',
ir.GrossRate, ir.AgencyCommissionPct,
ir.GrossRate * (1 - ir.AgencyCommissionPct) as 'NetRate',
TIHC.InvoiceDate
from [RadioDM].[Viero].tOrder_Current TOC
53 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Join [RadioDM].[Viero].tInvoiceHeader_Current TIHC
on TOC.SiteID = TIHC.SiteID
and TOC.OrderID = TIHC.OrderID
join [RadioDM].[Viero].tInvoiceRow IR
on TIHC.siteid=IR.Siteid
and TIHC.invoiceid=IR.invoiceid
left join [RadioDM].[Viero].tMiscRevLine_Current OL
on IR.siteid=ol.siteid
and ir.MiscRevenueLineNo=ol.MiscRevLineNo
left join [RadioDM].[Viero].tStation sta
on ol.SiteID=sta.SiteID
and ol.stationid=sta.StationID
join [RadioDM].[ERSP].tStation cl
on sta.EnterpriseStationID=cl.EnterpriseStationID
left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[DIMENSIONS] DIM (NOLOCK)
on cl.Description COLLATE DATABASE_DEFAULT =
LEFT(DIM.DESCRIPTION,7) COLLATE DATABASE_DEFAULT
where TOC.PackageCharge = 1
and TIHC.InvoiceRowType = 2
)
as qry2
LEFT join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxcust
on qry2.BillToCust=daxcust.ccarsourcecustomerid
and qry2.siteid=daxcust.CCARSITE
LEFT join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxadv
on qry2.AdvertiserID=daxadv.ccarsourcecustomerid
and qry2.siteid=daxadv.CCARSITE
where qry2.siteid in ('43','99','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318', '137',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
'102','110','118','120','122','134','151','155','157',
'159',
'158','160','163','165','175','181','187','188','192',
'194','243','247','258','268','275','277','294','306',
'312',
'168','240','290'
)
and qry2.InvoiceDate between @INVDTFROM and @INVDTTO
group by qry2.siteid, qry2.stationid,
qry2.BillToCust, qry2.AdvertiserID,
qry2.INVID, qry2.InvoiceDate,
54 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
daxcust.accountnum, daxadv.accountnum
-- This gives the list of Invoices associated with Sub Invoicing (Post
Migration).
Select distinct qry1.siteid, qry1.StationID, qry1.SubInvoices,
qry1.BillToCust, daxcust.accountnum as 'DAXBillTo',
qry1.AdvertiserID, daxadv.accountnum as 'DAXAdv',
qry1.BillDate,
sum(qry1.GrossRate) as 'SumGross',
sum(qry1.NetRate) as 'SumNet' from
(
Select distinct TMRC.SiteID, TMRC.InvoiceNo as 'SubInvoices',
'BillToCust' =
case
when TMRC.agencyid=0
then TMRC.advertiserid
else TMRC.AgencyID
end,
TMRC.advertiserid, DIM.NUM as 'StationID',
TMRC.BillDate, TMRC.GrossRate, TMRC.AgencyCommissionPct, TMRC.NetRate
from [RadioDM].[Viero].tMiscRevLine_Current TMRC
left join [RadioDM].[Viero].tStation sta
on TMRC.SiteID=sta.SiteID
and TMRC.stationid=sta.StationID
join [RadioDM].[ERSP].tStation cl
on sta.EnterpriseStationID=cl.EnterpriseStationID
left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[DIMENSIONS] DIM (NOLOCK)
on cl.Description COLLATE DATABASE_DEFAULT =
LEFT(DIM.DESCRIPTION,7) COLLATE DATABASE_DEFAULT
where tmrc.PrimaryAdvertiser = 0
)
as qry1
left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxcust
on Qry1.BillToCust=daxcust.ccarsourcecustomerid
and qry1.siteid=daxcust.CCARSITE
LEFT join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxadv
on qry1.AdvertiserID=daxadv.ccarsourcecustomerid
and qry1.siteid=daxadv.CCARSITE
where qry1.siteid in ('43','99','190','61','106', --Round 1
'57', '58', '70', '85', '89', '91', --Round 2
'93', '105', '112', '116', '121',
'125', '139', '143', '170', '180',
'215', '245', '248', '254', '272', '280', '288',
'24', '25', '32', '34', '41', '46', '50', '52', --Round 3
'53', '55', '59', '63', '65', '67', '69', '71',
'73', '76', '77', '92', '94', '95', '97', '101',
'113', '114', '117', '119', '124', '126', '127',
'128', '131', '132', '135', '146', '147', '150',
'152', '156', '161', '162', '166', '167', '171',
'173', '182', '183', '184', '185', '186', '193',
'241', '242', '244', '249', '250', '252', '261',
'270', '273', '279', '283', '284', '285', '289',
'293', '318', '137',
'12','14','16','17','19','26','27','28','35','37', --Round
4
'38','44','45','47','49','51','56','60','62','68',
'74','75','80','81','82','86','87','88','90','100',
55 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
'102','110','118','120','122','134','151','155','157',
'159',
'158','160','163','165','175','181','187','188','192',
'194','243','247','258','268','275','277','294','306',
'312',
'168','240','290'
)
and qry1.BillDate between @INVDTFROM and @INVDTTO
group by qry1.siteid, qry1.StationID, qry1.SubInvoices,
qry1.BillToCust, daxcust.accountnum,
qry1.AdvertiserID, daxadv.accountnum,
qry1.BillDate
Thiswill returnthe followingresults.
Step 8: RunDAX Queries(Trade Invoice Identification).sql. Make sure to change the dates. There is
one location for the date towards the middle ofthe script.
YOUSHOULD RUN THIS AT LEAST 6 DAYS BEFORE MONTH-END BEGINS. IT IS ALSO SUGGESTEDTHAT
YOURUN THIS EVERY FRIDAY.
Linkto Script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth
End ProceduresSQLScriptsDay2DAXQueries(Trade Invoice Identification) (3).sql
56 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Server: dwsqlclu8sql101
Database: Radio DM
Authentication: SQL ServerAuthentication
Log In: sqldev
Password: whatareyoudoing??
--Manual Invoice Load Reversal Trade and E-Commerce Reversals
select cij.CCArsite, cit.DIMENSION2_ AS 'BU', cij.ccarsourceinvoiceno,
CTAG.CCARSOURCECUSTOMERID, cij.invoiceaccount AS 'AXBillTo',
CTAD.CCARSOURCECUSTOMERID, cij.CCARADVERTISERNO AS 'AXAdvertiser',
sum(cit.LINEAMOUNT) as 'InvAmt',
cij.INVOICEID
from [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICETRANS cit
join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICEJOUR cij
on cit.INVOICEID=cij.INVOICEID
join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTTABLE CTAG
ON cij.INVOICEACCOUNT=CTAG.ACCOUNTNUM
join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTTABLE CTAD
ON cij.CCARADVERTISERNO=CTAD.ACCOUNTNUM
where cit.ITEMID in ('390','396','598','599', '400', '401')
and cit.INVOICEDATE between '08/01/2011' and '08/31/2011'
and cit.LINEAMOUNT <> 0
group by cij.CCArsite, cit.DIMENSION2_, cij.ccarsourceinvoiceno,
cij.invoiceaccount, CTAG.CCARSOURCECUSTOMERID,
CTAD.CCARSOURCECUSTOMERID, cij.CCARADVERTISERNO,
cij.INVOICEID
57 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
select SALESID, ITEMID, LINEPERCENT, LINEDISC, CCARAGENCYCOMMPCT
from [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].SALESLINE
where ITEMID in ('390','598','599', '400', '401','633')
and LINEPERCENT = 0
Thiswill returnthe followingresults. Normally,noresultsare returned. However,incase something
doesappear,thenproceedtostep 8(a).
Step 8(a): If youhave any resultsfromstep8, run the following update script
update dbo.SALESLINE
set LINEPERCENT=100-CCARAGENCYCOMMPCT
where ITEMID in ('390','598','599', '400', '401','633')
and LINEPERCENT=0
--Rows Affected (83)
Step 9: Run the RadioDM and DAX Queries(Manual InvoiceIdentification) v11a (draft). Makesure to
change the dates. WORK ONFIXING THE PROBLEM. – THE SCRIPT RETURNS NULL AND IT SHOULD
NOT.
CONSULTWITH STEVE SAMPERI,BUT YOUMOST LIKELY WILL NEED TO DELETE THIS STEP – CHECK ON
DAY 2 (10/4). USE THE SCRIPT THAT STEVE SAMPERI PROVIDED ON10/3. IF DOES NOT WORK,SKIP
THIS STEP AND PROCEED TO STEP 10 AND USE THAT SCRIPT AND COMBINE IT WITH THIS.
CHECK WITH SYLVIAFOWLER TO ENSURE SHE IS OKAY WITH THE NUMBER OF MANUALINVOICES.SHE
MAY REQUEST THAT THIS BE RE-RUN.
58 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
Linkto Script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth
End ProceduresSQLScriptsDay2RadioDMand DAXQueries(Manual Invoice Identification) v11a
(draft).sql
Server: dwsqlclu8sql101
Database: Radio DM
Authentication: SQL ServerAuthentication
Log In: sqldev
Password: whatareyoudoing??
--Daily Load Tie Out Query Detail (Manual Invoices-in DM not in AX)
declare @InvoiceMonth datetime
declare @InvDateTo datetime
set @InvoiceMonth='20110801'
set @InvDateTo='20110831'
--Site 44 Honolulu HI
SELECT qry3.SiteID, LBU.DIMENSION2_, qry3.InvoiceID,
BILLTO.accountnum AS 'AXBillto', BILLTO.ccarsourcecustomerid AS
'VIEROBillTo',
ADV.accountnum as 'AXAdv', ADV.ccarsourcecustomerid as 'VIEROAdv',
qry3.InvoiceMonth,
qry3.DMAmt--,
--CIJ.CCARSITE, CIJ.INVOICEID AS 'AXINV', CIJ.CCARSOURCEINVOICENO,
CIJ.invoiceaccount as 'AXAcct',
--CIJ.INVOICEAMOUNT, qry3.DMAmt-CIJ.INVOICEAMOUNT as 'Difference'
from
(
SELECT qry2.SiteID, qry2.InvoiceID, qry2.InvoiceMonth,
59 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
SUM(qry2.DMAmt) as 'DMAmt'
FROM
(
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '44'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '44'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '44'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '44'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
60 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '44'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
UNION
--Site 51 Phoenix AZ
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '51'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '51'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
61 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '51'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '51'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '51'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
UNION
--Site 68 Sarasota FL
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
62 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '68'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '68'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '68'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '68'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '68'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
63 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
UNION
--Site 81 Orlando FL
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '81'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '81'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '81'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
64 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '81'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '81'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
UNION
--Site 110 Albuquerque NM
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '110'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
65 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '110'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '110'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '110'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate
from Viero.tMiscRevLine_Current mrc
join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '110'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
)
group by SiteID, InvoiceID, InvoiceMonth
UNION
--Site 268 Farmington NM
select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
66 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz)
SUM(qry1.LineAmt) as 'DMAmt' from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from Viero.tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '268'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
--Misc Invoice Rows
select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth,
mrc.InvNetRate as 'DMAmt'
from Viero.tMiscRevLine_Current mrc
join Viero.tInvoiceHeader_Current ih (nolock)
on mrc.SiteID=ih.SiteID
and mrc.InvoiceNo=ih.InvoiceID
where ih.SiteID = '268'
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
and ih.InvoiceRowType=2
and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633)
)
as qry1
group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth
UNION
--Radio DM Query for Daily Load Tax Calculation
select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax'
from viero.tinvoiceheader_current
where siteid = '268'
and invoiceid in (
select qry1.invoiceid from
(
select ir.SiteID, ir.invoiceID, ih.InvoiceMonth,
sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct *
count(ir.OrderLineNo)) as LineAmt
from [RadioDM].[Viero].tInvoiceRow ir (nolock)
join viero.tInvoiceHeader_Current ih (nolock)
on ir.SiteID=ih.SiteID
and ir.InvoiceID=ih.InvoiceID
and ir.InvoiceRowType=ih.InvoiceRowType
where ih.SiteID = '268'
and ih.InvoiceRowType=1
and ir.Autofill=0
and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
--and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633)
GROUP BY ir.SiteID, ir.invoiceID,
ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
union all
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)
PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)

More Related Content

Viewers also liked

Γυναικολόγος Κατερίνα Γεωργαντοπούλου
Γυναικολόγος Κατερίνα ΓεωργαντοπούλουΓυναικολόγος Κατερίνα Γεωργαντοπούλου
Γυναικολόγος Κατερίνα ΓεωργαντοπούλουKaterina Georgantopoulou
 
JED+Final%2BPresentation%2BSlides
JED+Final%2BPresentation%2BSlidesJED+Final%2BPresentation%2BSlides
JED+Final%2BPresentation%2BSlidesZaheer Narejo
 
Idea Lab_Zaheer Narejo
Idea Lab_Zaheer NarejoIdea Lab_Zaheer Narejo
Idea Lab_Zaheer NarejoZaheer Narejo
 
7Habits_Zaheer Narejo
7Habits_Zaheer Narejo7Habits_Zaheer Narejo
7Habits_Zaheer NarejoZaheer Narejo
 

Viewers also liked (6)

Γυναικολόγος Κατερίνα Γεωργαντοπούλου
Γυναικολόγος Κατερίνα ΓεωργαντοπούλουΓυναικολόγος Κατερίνα Γεωργαντοπούλου
Γυναικολόγος Κατερίνα Γεωργαντοπούλου
 
Cause and effect
Cause and effectCause and effect
Cause and effect
 
JED+Final%2BPresentation%2BSlides
JED+Final%2BPresentation%2BSlidesJED+Final%2BPresentation%2BSlides
JED+Final%2BPresentation%2BSlides
 
smART Presentation
smART Presentation smART Presentation
smART Presentation
 
Idea Lab_Zaheer Narejo
Idea Lab_Zaheer NarejoIdea Lab_Zaheer Narejo
Idea Lab_Zaheer Narejo
 
7Habits_Zaheer Narejo
7Habits_Zaheer Narejo7Habits_Zaheer Narejo
7Habits_Zaheer Narejo
 

Similar to PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)

Two stage op amp design on cadence
Two stage op amp design on cadenceTwo stage op amp design on cadence
Two stage op amp design on cadenceHaowei Jiang
 
EvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfEvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfPraveenPolu1
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answersNawaz Sk
 
Shoc proposal dec 2013 rev.01_ok
Shoc proposal dec 2013 rev.01_okShoc proposal dec 2013 rev.01_ok
Shoc proposal dec 2013 rev.01_okFitri Ifony
 
Safety stock ASCP safety stock
Safety stock ASCP safety stockSafety stock ASCP safety stock
Safety stock ASCP safety stockRamalingam0104
 
ThruPut Manager AE+: Automation for Production Control and Capacity Management
ThruPut Manager AE+: Automation for Production Control and Capacity ManagementThruPut Manager AE+: Automation for Production Control and Capacity Management
ThruPut Manager AE+: Automation for Production Control and Capacity ManagementCA Technologies
 
SAP T-Accounts Posting Simulation - Example
SAP T-Accounts Posting Simulation - ExampleSAP T-Accounts Posting Simulation - Example
SAP T-Accounts Posting Simulation - ExampleMichael Knowles
 
Dada enterprise cost management solution comparisons
Dada enterprise cost management solution comparisonsDada enterprise cost management solution comparisons
Dada enterprise cost management solution comparisonsSachin Melwani
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersConnor McDonald
 
zen and the art of SQL optimization
zen and the art of SQL optimizationzen and the art of SQL optimization
zen and the art of SQL optimizationKaren Morton
 
Accounting Global 9th Edition Horngren Solutions Manual
Accounting Global 9th Edition Horngren Solutions ManualAccounting Global 9th Edition Horngren Solutions Manual
Accounting Global 9th Edition Horngren Solutions Manualmelofufa
 
Production & Operation Management Chapter9[1]
Production & Operation Management Chapter9[1]Production & Operation Management Chapter9[1]
Production & Operation Management Chapter9[1]Hariharan Ponnusamy
 
Solutions manual for financial accounting 9th edition by weygandt
Solutions manual for financial accounting 9th edition by weygandtSolutions manual for financial accounting 9th edition by weygandt
Solutions manual for financial accounting 9th edition by weygandtkencal3243
 
SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9Umair Amjad
 

Similar to PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311) (20)

S curve tutorial1
S curve tutorial1S curve tutorial1
S curve tutorial1
 
S curve tutorial1
S curve tutorial1S curve tutorial1
S curve tutorial1
 
Two stage op amp design on cadence
Two stage op amp design on cadenceTwo stage op amp design on cadence
Two stage op amp design on cadence
 
EvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfEvolveExecutionPlans.pdf
EvolveExecutionPlans.pdf
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 
Shoc proposal dec 2013 rev.01_ok
Shoc proposal dec 2013 rev.01_okShoc proposal dec 2013 rev.01_ok
Shoc proposal dec 2013 rev.01_ok
 
Safety stock ASCP safety stock
Safety stock ASCP safety stockSafety stock ASCP safety stock
Safety stock ASCP safety stock
 
ThruPut Manager AE+: Automation for Production Control and Capacity Management
ThruPut Manager AE+: Automation for Production Control and Capacity ManagementThruPut Manager AE+: Automation for Production Control and Capacity Management
ThruPut Manager AE+: Automation for Production Control and Capacity Management
 
Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
SAP T-Accounts Posting Simulation - Example
SAP T-Accounts Posting Simulation - ExampleSAP T-Accounts Posting Simulation - Example
SAP T-Accounts Posting Simulation - Example
 
Dada enterprise cost management solution comparisons
Dada enterprise cost management solution comparisonsDada enterprise cost management solution comparisons
Dada enterprise cost management solution comparisons
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
 
zen and the art of SQL optimization
zen and the art of SQL optimizationzen and the art of SQL optimization
zen and the art of SQL optimization
 
Sql queries
Sql queriesSql queries
Sql queries
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Accounting Global 9th Edition Horngren Solutions Manual
Accounting Global 9th Edition Horngren Solutions ManualAccounting Global 9th Edition Horngren Solutions Manual
Accounting Global 9th Edition Horngren Solutions Manual
 
Production & Operation Management Chapter9[1]
Production & Operation Management Chapter9[1]Production & Operation Management Chapter9[1]
Production & Operation Management Chapter9[1]
 
Chapter9[1]
Chapter9[1]Chapter9[1]
Chapter9[1]
 
Solutions manual for financial accounting 9th edition by weygandt
Solutions manual for financial accounting 9th edition by weygandtSolutions manual for financial accounting 9th edition by weygandt
Solutions manual for financial accounting 9th edition by weygandt
 
SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9
 

PROCEDURE FOR MONTH END DAY 2 & 3 (Final rev 100311)

  • 1. 1 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) PROCEDURE FOR MONTH-END DAYS 2 (AM & PM) & 3 (AM) NOTE: MANY OF THE SCREEN SHOTS ARE FOR INFORMATIONAL PURPOSES ONLY—THEY MAY NOT MATCH THE DATA IN A PREVIOUS SCREEN SHOT. DAY 2 (AM) Step 1: You will receive anupdated Excel file fromJeanaLackey [see steps 5(g) and5(g)(1) fromDay1]. BUSINESS_UNIT Correct BU NAME1 ACCOUNT Correct Account DEPTID Correct Dept 65512 65525 WKGR-FM-WestPalmBeach,FL 493000 0 67111 65525 WZZR-FM-WestPalmBeach,FL 493000 0 26123 KOA-AM-Denver,CO 500000 0 110 53111 53115 WFBQ-FM-Indianapolis,IN 560800 731 64121 64127 WGST-AM-Atlanta,GA 560800 731 65321 65337 WBTP-FM-Tampa,FL 560800 731 65611 65619 WMGF-FM-Orlando,FL 560800 731 67211 67217 WBVD-FM-Melbourne,FL 560800 731 71123 71127 WKKF-FM-Albany,NY 560800 731 71511 71526 WKGS-FM-Rochester,NY 561300 113 15737 15737 SharedServ-SanFrancisco,CA 820000 0 731 Step 1(a): Run the MBR COMBO EDITS-SECONDPASS-REPORTEDTOACCOUNTINGscript. Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth End ProceduresSQLScriptsDay2MBRCOMBO EDITS-SECONDPASS-REPORTEDTOACCOUNTING(Run DuringMBR Cash Month EndCycle) (6).sql ServerName: pssqlclusfnprod Database: FNPROD Authentication: SQL ServerAuthentication Log In: sqldev Password: whatareyoudoing?? Step 1(a)(1):You will needtorunthe following --SELECT count (*) Statement dependingon whetherthe correctionisa BusinessUnit(BU),Accountor Department ID. The SET BUSINESS_UNIT, SET ACCOUNTandSET DEPTID numberis the correct number. The WHERE BUSINESS_UNIT,AND ACCOUNT,ANDDEPTID number will be the incorrect BusinessUnit, Accountor DepartmentID.
  • 2. 2 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Make sure to enterthe current valuesbefore proceedingand run each script independentlybasedon the correctionthat needsto be done. STOP: DO NOT INCLUDE THE UPDATE AS PART OF RUNNING THE SCRIPT; HOWEVER, YOUMUST CORRECT THE SET BUSINESSUNIT IN THE UPDATE SCRIPT AS PART OFTHE NEXT STEP. --Business Unit Update UPDATE PS_CCW_JRNL_LN SET BUSINESS_UNIT = '71526' ----SELECT count (*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '71511' AND ACCOUNT = '561300' AND DEPTID = '113' ----ROWS = 1 --Account Update UPDATE PS_CCW_JRNL_LN SET ACCOUNT = '214100' ---- SELECT count(*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '36320' AND ACCOUNT = '214000' AND DEPTID = '000' AND APPL_JRNL_ID='MBR_AUTO' ----ROWS = 1
  • 3. 3 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) --Department Update UPDATE PS_CCW_JRNL_LN SET DEPTID='731' ----SELECT count (*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '15737' AND ACCOUNT = '820000' AND DEPTID = '000' ----ROWS = 1 Dependingonwhichscriptwasused,one of the followingresultswillappear. These are examplesonly, the resultswill normallyreturn1. BusinessUnitUpdate Account Update
  • 4. 4 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Department Update Step 1(a)(2): Once youhave correctedthe UPDATE scriptand ----SELECT count (*) statement, run the entire scripttoupdate the BU, Accountand DeptID. Make sure to run each script independentlybasedonthe correctionthatneedstobe made. --Business Unit Update UPDATE PS_CCW_JRNL_LN SET BUSINESS_UNIT = '71526' ----SELECT count (*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '71511' AND ACCOUNT = '561300' AND DEPTID = '113' ----ROWS = 1 --Account Update UPDATE PS_CCW_JRNL_LN SET ACCOUNT = '214100' ---- SELECT count(*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '36320' AND ACCOUNT = '214000' AND DEPTID = '000' AND APPL_JRNL_ID='MBR_AUTO' ----ROWS = 1
  • 5. 5 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) --Department Update UPDATE PS_CCW_JRNL_LN SET DEPTID='731' ----SELECT count (*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '15737' AND ACCOUNT = '820000' AND DEPTID = '000' ----ROWS = 1 Dependingonwhichscriptwasused,one of the followingresultswillappear. These are examplesonly. BusinessUnitUpdate Account Update
  • 6. 6 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Department Update Step 1(b): To ensure thatyouhave correctedall the BU’s, Account andDepartmentID runthe following script. Make sure to change the date. /*********** SQL TO DETERMINE FAILED COMBO EDITS (AFTER INITIAL COMBO EDIT SCRUBBING)***********************/ SELECT DISTINCT J.BUSINESS_UNIT,M.NAME1, J.ACCOUNT, J.DEPTID, LINE_DESCR, FOREIGN_AMOUNT, JOURNAL_DATE FROM PS_CCW_JRNL_LN as J WITH (NOLOCK) JOIN PS_CCW_JRNL_HDR AS H WITH (NOLOCK) ON H.CCW_JRNL_SRC_ID = J.CCW_JRNL_SRC_ID LEFT OUTER JOIN /*FNPROD_READER.FNPROD.*/dbo.PS_CCW_DEPT_CE_VW AS C --WITH (NOLOCK) Combo Edit View ON J.BUSINESS_UNIT = C.BUSINESS_UNIT AND J.ACCOUNT = C.ACCOUNT AND J.DEPTID = C.DEPTID JOIN PS_CCW_MBR_STATION AS M WITH (NOLOCK) ON M.BUSINESS_UNIT = J.BUSINESS_UNIT WHERE JOURNAL_DATE BETWEEN '08/1/11' AND '08/31/11' AND C.BUSINESS_UNIT IS NULL AND J.APPL_JRNL_ID='MBR_AUTO' --AND J.ACCOUNT NOT IN ('420750','420760','214100','214300','214500','551200','560005','560000','550 000','560800','800000','810200','822000','822000','810000','561300','561400', '561500') --AND J.DEPTID <> '0' ORDER BY J.ACCOUNT, J.BUSINESS_UNIT
  • 7. 7 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) The resultshouldcome backblank. If not,thenyouhave made an erroror you may nothave captured all the corrections. Go back to the excel file andre-runthe corrections. Step 2: Runthe ----SELECT * Statementportionof the Update Statementof ImportStatusscript. Thisis the same numberof failedJournal Entries (‘F”) returnedinthe PeopleSoft reportof Step6(c) of Day 1. STOP: DO NOT INCLUDE THE UPDATE AS PART OF RUNNING THE SCRIPT. /************************ UPDATE STATEMENT FOR IMPORT STATUS ******************************/ UPDATE PS_CCW_JRNL_HDR SET CCW_IMPORT_STATUS = 'R' ----SELECT * FROM PS_CCW_JRNL_HDR WHERE CCW_IMPORT_STATUS = 'F' ----ROWS = 12
  • 8. 8 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) The followingresultwillappear. Step 2(a): Run the UPDATE scriptto verifyyourrow counts. Thischangesthe “F” to “R”. F = Failed R = Ready /************************ UPDATE STATEMENT FOR IMPORT STATUS ******************************/ UPDATE PS_CCW_JRNL_HDR SET CCW_IMPORT_STATUS = 'R' ----SELECT * FROM PS_CCW_JRNL_HDR WHERE CCW_IMPORT_STATUS = 'F' ----ROWS = 12 The followingresultwillappear. If the row countsdo not match the row countsinyour updated row countsfrom the scriptabove,youhave made an error.
  • 9. 9 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 3: Email or walkoverto DavidDe La Fuente andlethimknow that he can run the importjournal. If David runsthe importjournal and discoversafailedjournal,proceedtostep3(b). Youcan check the statusof the processinPeopleSoftbyviewingthe ProcessMonitor. Link to PeopleSoft: https://fnprod.mssql.peoplesoft.clearchannel.com/psp/ps/EMPLOYEE/PSFT_EP/?cmd=logout UserID: JE_SYSTEM_USER Password: Meatloaf
  • 10. 10 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 3(a): Run the followingbabysit scriptforImportJournals. Youwill see the numberof successful and readyjournals(these are the onesyourcorrectedinstep1). The numberof “R” importsshould equal the numberof rowcounts that appearsinthe screenshotfor steps2 and 2(a). You cannot proceedto the next stepuntil this is done. S= Success R=Ready /************************ BABYSIT STATEMENT FOR IMPORTJOURNALS PS JOB ******************************/ --Run this journal to babysit IMPORTJOURNALS PS Job select CCW_IMPORT_STATUS, COUNT(*) from PS_CCW_JRNL_HDR WITH (NOLOCK) WHERE APPL_JRNL_ID='MBR_AUTO' GROUP BY CCW_IMPORT_STATUS
  • 11. 11 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 3(b): To findthe failedjournal,runthe followingscript. Thisisdone on an exceptionbasis.Make sure to run both scripts at the same time. If you needassistance for this process,contact Kushan Edussuriya or David De La Fuente.Make a note of the BU listedunderBUSINESS_UNIT,Invoice number listedunderLINE_DESCR. /********************* FAILED JOURNAL *********************************/ --Run this to find any failed journals select * from PS_CCW_JRNL_HDR WITH (NOLOCK) WHERE APPL_JRNL_ID='MBR_AUTO' and CCW_IMPORT_STATUS='F' select * from PS_CCW_JRNL_LN WHERE APPL_JRNL_ID='MBR_AUTO' AND CCW_JRNL_SRC_ID='3589' The script will returnthe followingresult.
  • 12. 12 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 3(b)(1): Go to AXto lookat the BU to see whatit contains.AXGeneralLedgerDimensions> Change Dimensionto Station>insertBU. You will notice the BUdoesexistinAXbutfor some reason doesnotexistinPeopleSoft. Step 3(b)(2): Go toPeopleSofttolocate the businessUnit. PeopleSoftSetUpFinancials/Supply ChainBusinessUnitRelatedGeneral LedgerGeneral LedgerDefinitionEnterthe BU and see what resultyouget. Normally,youwill see thatPeopleSoftdoesnothave the BU. Linkto PeopleSoft: https://fnprod.mssql.peoplesoft.clearchannel.com/psp/ps/EMPLOYEE/PSFT_EP/?cmd=logout UserID: JE_SYSTEM_USER Password: Meatloaf
  • 13. 13 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 3(b)(3): To correctthe problem,youwill needtoreviewthe Journal andInvoice. Tofindthe Journal go to AXGeneral LedgerReportsPostedtransactionsbyjournalClickSelectChangeFieldto VoucherandCriteriato the invoice number. Itwill returnaJournal Voucher. Step 3(b)(4): Insertthe Vouchernumberintothe criteriafield. Youcan obtainthat numberfromstep 3(b).ClickOkay.
  • 14. 14 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) ClickOkayon the PostedtransactionbyJournal – Reportscreenand hitokayonce againon the Posted by Journal screen. The followingscreenwill appear. Make a note of the JV number. Step 3(b)(4): You will thenneedtoreview the lines forthe Journal bygoingtoAXAccounts ReceivablesPaymentJournalInsertJV number>SelectLines
  • 15. 15 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 3(b)(5): Locate the SharedServicesBU forthissite by goingto AXGeneral LedgerDimensionsStation>InsertSite #. Step 3(b)(6): Run the----SELECT count (*) Statementtoget the row count and update the BU (see step1 on where toenterfailedandcorrectBU): --Business Unit Update UPDATE PS_CCW_JRNL_LN SET BUSINESS_UNIT = '52222' ----SELECT count (*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '55211' AND ACCOUNT = '560005' AND DEPTID = '598' ----ROWS = 1 Step 3(b)(7): Run the UPDATE script. --Business Unit Update UPDATE PS_CCW_JRNL_LN SET BUSINESS_UNIT = '52222' ----SELECT count (*) FROM PS_CCW_JRNL_LN WHERE BUSINESS_UNIT = '55211' AND ACCOUNT = '560005' AND DEPTID = '598' ----ROWS = 1 Step 3(b)(8): Run the ImportJournal Script referencedinstep3(a) until yousee “S.” ************************ BABYSIT STATEMENT FOR IMPORTJOURNALS PS JOB ******************************/ --Run this journal to babysit IMPORTJOURNALS PS Job select CCW_IMPORT_STATUS, COUNT(*) from PS_CCW_JRNL_HDR WITH (NOLOCK) WHERE APPL_JRNL_ID='MBR_AUTO' GROUP BY CCW_IMPORT_STATUS
  • 16. 16 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Example of Successful ImportJournal S = Success Step 4: Runthe MBR ExceptionQueriesScript. Make sure to change the journal date and transdate. Note: This step is notdependent on the prior step. Look for NULL (couldbe in BU or other columns – a.k.ain SQL Script as CCARSite). Linkto obtainscript: CCIFS1SATCommonFinancialInfoSystems&ReportingAX QueriesMonthendMonthEndProceduresSQLScriptsDay2MBRExceptionQueries(4).sql Server: AXSQLCluster Database: AX Reporting Authentication: WindowsAuthentication
  • 17. 17 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) --MBR Exception Queries select distinct mbrex.ProcessID, mbrex.DataFlowDesc, mbrex.TransformationDesc, mbrex.CCARSite, mbrex.AccountNum, mbrex.VoucherNum, mbrex.BusinessUnit '08/31/2011' AS 'Journal Date', mbrex.DeptID, mbrex.ForeignAmount, jrnlsub.JOURNALNUM, jrnlsub.JOURNALNUM+'-'+jrnlsub.VOUCHER as 'LineDesc', ErrorDesc from MBREXCEPTIONS mbrex (nolock), (select distinct LJT.VOUCHER, LJT.JOURNALNUM from AXLEDGERJOURNALTRANS ljt (nolock) where TRANSDATE between '20110801' and '20110831' ) as jrnlsub WHERE mbrex.IsError=1 AND mbrex.VoucherNum NOT LIKE 'INV%' and jrnlsub.voucher=mbrex.VoucherNum order by mbrex.VoucherNum select * from MBREXCEPTIONS (nolock) where VoucherNum not like 'INV%' order by VoucherNum The followingresultswill be returned. Step 4(a): Copyand paste the data only (donot copy the headers) fromthe SQLscript andput intothe excel file underthe tab,“RawFile.” The template forthisexcel file canbe foundbygoingto ccifs1satcommonFinancialInfoSystems&ReportingAXQueriesMonthendMonthEnd ProceduresTemplate Documents2011MBR JET Cash ExceptionTemplate(rev080511).xlsx The Excel file contains formulasand pre-populatedinformationinthe tab marked “JET”,so do not make any changes to those cells.
  • 18. 18 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) In the scriptabove,youwill receive severalNULL’sforthe BU. FilteroutanyBU that isNULL. You must populate those NULL’s. Step 4(b): Locate the SharedServicesBUfor the NULL BU’s bygoingto AX>General Ledger>Dimensions>Station>Site>InsertSite forBU that isNULL. Enterthe BU numberforthe Shared Servicesintothe excel file underthe tablabeled,“Raw File.”
  • 19. 19 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Make sure to un-filterandun-highlightthe databefore sendingittoAR. Step 4(c): Go to the excel tablabeled,“JET”and note the following:  Change the AccountingDate (ColumnA) inthe M/DD/YY format andmake sure to carry itall the waydown. For example,forthe August close,we usedadate of 8/01/11.  KeepProjectID- Chartfield1(ColumnF),andOper.Unit(ColumnI) blank.  BusinessUnitLine (ColumnB),Account(ColumnC), Amount(ColumnE),andLine Description (ColumnH) containformulas,whichwill autopopulate.  DepartmentID(ColumnD),Jrnl Line Ref (ColumnG) andCurrencyCD (ColumnJ) containpre- populatedinformation. DONOT INSERT ANYTHING INTO THESE COLUMNS. Make sure to save thisfile usingthe followingpath: NetworkCCIFS1SATCommonFinancial Info Systems&ReportingAXQueriesMonthendMonthEndProcedures>(lookforfolderwiththe correspondingmonthyouare closingi.e. “September2011 Close Document”forAugustclose). Make sure to convert thisinto a “text” filebefore saving.
  • 20. 20 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 4(d): Sendthe file toJeanaLackey and copySylviaFowler(Director –FIS). Day 2 (PM) – Day 3 (AM) Step 5: Run RadioDM Queries(Invoice Tie Out-DailyLoads-Summaryof Sites-IncludingBill Payer).sql. Make sure to change the dates (locatedin two area’s inthe script). Make sure to run entire script. YOUCAN NOT PROCEED UNTIL YOUHAVE HEARD FROM SYLVIAFOWLER. WE ARE WAITING FORTHE CALANDER INVOICELOAD FROM RADIO DM TO AX. Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth End ProceduresSQLScriptsDay2RadioDMQueries(Invoice Tie Out-DailyLoads-Summaryof Sites- IncludingBill Payer) (3).sql Server: dwsqlclu8sql101 Database: Radio DM Authentication: SQL ServerAuthentication Log In: sqldev Password: whatareyoudoing??
  • 21. 21 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) declare @InvoiceMonth datetime declare @InvDateTo datetime set @InvoiceMonth='2011-08-01' set @InvDateTo='2011-08-31' --Daily Load Tie Out Query Detail (Radio DM) with Sales Tax Included-Summary --Make one query for each site with Sales Tax SELECT QRY3.SITEID, QRY3.SITENAME, SUM(QRY3.DMAMT) FROM ( --Site 44 Honolulu HI SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) AS 'DMAMT' FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '44' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID
  • 22. 22 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '44' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '44' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '44' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '44' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName UNION ALL
  • 23. 23 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) --Site 51 Phoenix AZ SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '51' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '51' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '51' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '51' and ih.InvoiceRowType=1 and ir.Autofill=0
  • 24. 24 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '51' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName UNION ALL --Site 68 Sarasota FL SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '68' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt'
  • 25. 25 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '68' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '68' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '68' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '68' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID
  • 26. 26 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) group by qry2.SiteID, st.SiteName UNION ALL --Site 81 Orlando FL SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '81' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '81' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '81' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType
  • 27. 27 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) where ih.SiteID = '81' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '81' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName UNION ALL --Site 110 Albuquerque NM SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '110' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth
  • 28. 28 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '110' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '110' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '110' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '110' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth
  • 29. 29 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName UNION ALL --Site 268 Farmington NM SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '268' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '268' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '268' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock)
  • 30. 30 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '268' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '268' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName UNION ALL --Site 294 Gallup NM SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '294' and ih.InvoiceRowType=1 and ir.Autofill=0
  • 31. 31 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '294' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '294' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '294' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '294' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) )
  • 32. 32 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName UNION ALL --Site 306 Florida Keys FL SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '306' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '306' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '306' and invoiceid in ( select qry1.invoiceid from (
  • 33. 33 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '306' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '306' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName UNION ALL --Site 312 West Palm Beach FL SELECT qry2.SiteID, st.sitename, SUM(qry2.DMAmt) FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID
  • 34. 34 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '312' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '312' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION ALL --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '312' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '312' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '312' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
  • 35. 35 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.SiteID, st.SiteName --End Daily Load Tie Out Query Detail (Radio DM) with Tax Included-Summary UNION ALL --Daily Load Tie Out Query Summary (Radio DM-Non Tax Sites) select qry2.siteid, st.sitename, SUM(qry2.LineTot) from ( select qry1.siteid, SUM(qry1.LineAmt) as 'LineTot' from ( select ir.SiteID, ih.Orderid, ir.invoiceID, ir.EnterpriseRevenueTypeID, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID in ('43','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','45','47','49','56','60','62', '74','75','80','82','86','87','88','90','100', '102','118','120','122','134','151','155','157', '159', '158','160','163','165','168','175','181','187','188','192', '194','243','247','258','275','277','240','290' ) and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
  • 36. 36 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ir.EnterpriseRevenueTypeID, ir.grossrate, ir.AgencyCommissionPct ) as qry1 group by qry1.SiteID UNION ALL --Misc Invoice Rows select mrc.SiteID, sum(mrc.InvNetRate) from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID in ('43','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','45','47','49','56','60','62', '74','75','80','82','86','87','88','90','100', '102','118','120','122','134','151','155','157', '159', '158','160','163','165','168','175','181','187','188','192', '194','243','247','258','275','277','240','290' ) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) group by mrc.SiteID ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID group by qry2.siteid, st.SiteName UNION ALL --Bill Payer Daily Load Tie Out Query Summary (Radio DM) SELECT qry2.SiteID, st.SiteName, SUM(qry2.DMAmt)/2 FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
  • 37. 37 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID in (396,398,399,597) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth UNION ALL --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID in (396,398,399,597) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID where qry2.SiteID in ('43','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100', '102','110','118','120','122','134','151','155','157', '159', '158','160','163','165','175','181','187','188','192',
  • 38. 38 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) '194','243','247','258','268','275','277','294','306', '312', '168','240','290' ) group by qry2.SiteID, st.SiteName UNION ALL --Affiliate Queries Bill Payer (Summary) from Radio DM (Sacramento) select qry2.siteid, st.SiteName, SUM(qry2.LineTot)/2 from ( select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS 'LineTot' from ( select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, l.StationID, sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID and ir.SiteID = l.SiteID where ih.SiteID in ('99') and l.StationID not in (35,36,37,38,39,40) and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID in (396,398,399,597) GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, ir.grossrate, ir.AgencyCommissionPct, l.StationID ) as qry1 group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth UNION ALL select mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth, sum(mrc.InvNetRate) from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID in ('99') and mrc.StationID not in (35,36,37,38,39,40) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID in (396,398,399,597) group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth ) AS QRY2 join dbo.tSite st on qry2.SiteID=st.SiteID GROUP BY qry2.siteid, st.SiteName
  • 39. 39 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) UNION ALL --Affiliate Queries Bill Payer (Summary) from Radio DM (Salt Lake City) select qry2.siteid, st.SiteName, SUM(qry2.LineTot)/2 from ( select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS 'LineTot' from ( select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, l.StationID, sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID and ir.SiteID = l.SiteID where ih.SiteID in ('137') and l.StationID not in (73) and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID in (396,398,399,597) GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, ir.grossrate, ir.AgencyCommissionPct, l.StationID ) as qry1 group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth UNION ALL select mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth, sum(mrc.InvNetRate) from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID in ('137') and mrc.StationID not in (73) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID in (396,398,399,597) group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth ) AS QRY2 join dbo.tSite st on qry2.SiteID=st.SiteID GROUP BY qry2.siteid, st.SiteName UNION ALL --Bill Payer Summary (Sacramento) select qry2.siteid, st.sitename, sum(qry2.LineTot) from (
  • 40. 40 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS 'LineTot' from ( select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, l.StationID, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID and ir.SiteID = l.SiteID where ih.SiteID in ('99') and l.StationID not in (35,36,37,38,39,40) and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, ir.grossrate, ir.AgencyCommissionPct, l.StationID ) as qry1 group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth UNION ALL select mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth, sum(mrc.InvNetRate) from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID in ('99') and mrc.StationID not in (35,36,37,38,39,40) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth ) AS QRY2 join dbo.tSite st on qry2.SiteID=st.SiteID GROUP BY qry2.siteid, st.SiteName UNION ALL --Bill Payer Summary (Salt Lake City) select qry2.siteid, st.sitename, sum(qry2.LineTot) from ( select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS 'LineTot' from ( select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, l.StationID,
  • 41. 41 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID and ir.SiteID = l.SiteID where ih.SiteID in ('137') and l.StationID not in (73) and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, ir.grossrate, ir.AgencyCommissionPct, l.StationID ) as qry1 group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth UNION ALL select mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth, sum(mrc.InvNetRate) from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID in ('137') and mrc.StationID not in (73) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth ) AS QRY2 join dbo.tSite st on qry2.SiteID=st.SiteID GROUP BY qry2.siteid, st.SiteName ) AS QRY3 GROUP BY qry3.siteid, QRY3.SiteName order by QRY3.siteid ----------------------------------------------------------------------------- -------------------------- --Daily Load Tie Out Query Summary (DAX) with Sales Tax Included select qry1.ccarsite, SUM(qry1.AXAmt) as 'AXSum' from ( --Invoice Load (Excluding Trade) select CCARSITE, INVOICEID, CCARSOURCEINVOICENO, SUM(INVOICEAMOUNT) as 'AXAmt' from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTINVOICEJOUR] with (nolock) WHERE CCARSITE in ('43','99','190','61','106', --Round 1
  • 42. 42 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152',Is th '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '137', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100', '102','110','118','120','122','134','151','155','157', '159', '158','160','163','165','175','181','187','188','192', '194','243','247','258','268','275','277','294','306','312', '168','240','290' ) --AND INVOICEDATE BETWEEN @InvoiceMonth AND @InvDateTo AND INVOICEDATE BETWEEN '20110801' AND '20110831' AND INVOICEID NOT LIKE 'CRD%' and CCARINVOICEACTION='0' GROUP BY CCARSITE, INVOICEID, CCARSOURCEINVOICENO HAVING SUM(INVOICEAMOUNT) <> 0 UNION ALL --Manual Invoices select b.CCARSITE, A.VOUCHER, a.ccarsourceorderno, SUM(amountcur) as 'AXAmt' from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[ccarCUSTTRANSdetail] a with (nolock) join [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTTABLE] b with (nolock) on a.accountnum = b.ACCOUNTNUM --where TRANSDATE BETWEEN @InvoiceMonth AND @InvDateTo where TRANSDATE BETWEEN '20120501' AND '20120531' AND B.CCARSITE in ('43','99','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '137',
  • 43. 43 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100', '102','110','118','120','122','134','151','155','157', '159', '158','160','163','165','175','181','187','188','192', '194','243','247','258','268','275','277','294','306', '312', '168','240','290' ) and a.dimension2_ <> '97000' and ( (a.voucher BETWEEN 'MINV-000009925' AND 'MINV-000009994') or --Manual Invoices (JV00180151) (a.voucher BETWEEN 'MINV-000009995' AND 'MINV-000010044') --Correcting Entries (JV00179906 and JV00180302) ) Group by b.ccarsite, A.VOUCHER, a.ccarsourceorderno ) as qry1 group by qry1.ccarsite order by cast(qry1.ccarsite as int) It will returnthe followingresult. Step 5(a): Copyand Paste the data intothe excel sheettitled“Invoice Tie”inthe tab labeled,“Tie Out.” The firsthalf of the scriptwill be pastedintocolumnsA – C andthe secondhalf of the scriptwill be patedintocolumnsD – F. The useof column G will be explained later. Make sure not to include the headers.
  • 44. 44 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) NOTE: MANY OFTHE FIELDS IN THE EXCEL DOCUMENT CONTAINSFORMULAS. THOSE CELLS ARE PROTECTED. Linkfor template document: CCIFS1SATCommonFinancial InfoSystems&ReportingAX QueriesMonthendMonthEndProceduresTemplate DocumentsInvoice Tie OutTemplate.xlsx Make sure to save a copy usingthe followingpath: NetworkCCIFS1SATCommonFinancial Info Systems&ReportingAXQueriesMonthendMonthEndProcedures>(lookforfolderwiththe correspondingmonthyouare closingi.e.“September2011 Close Document”forAugustclose). Step 6: RunRadio DMQueries(Invoice Tie Out-DailyLoads-Summaryof Sites-Bill PayerInvoices).sql. Make sure to change the dates. There are two locationsforthe date. Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth End ProceduresSQLScriptsDay2RadioDMQueries(Invoice Tie Out-DailyLoads-Summaryof Sites-Bill PayerInvoices).sql Server: dwsqlclu8sql101 Database: Radio DM Authentication: SQL ServerAuthentication Log In: sqldev Password: whatareyoudoing??
  • 45. 45 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) declare @InvoiceMonth datetime declare @InvDateTo datetime set @InvoiceMonth='2011-08-01' set @InvDateTo='2011-08-31' --Daily Load Tie Out Query (Summary) SELECT QRY3.SITEID, QRY3.SITENAME, SUM(QRY3.DMAMT) FROM ( --Bill Payer Daily Load Tie Out Query Summary (Radio DM) SELECT qry2.SiteID, st.SiteName, SUM(qry2.DMAmt)/2 as 'DMAmt' FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID in (396,398,399,597) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID in (396,398,399,597) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) as qry2 join dbo.tSite st on qry2.SiteID=st.SiteID where qry2.SiteID in ('43','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171',
  • 46. 46 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100', '102','110','118','120','122','134','151','155','157', '158','160','163','165','175','181','187','188','192', '194','243','247','258','268','275','277','294','306', '312', '168','240','290' ) group by qry2.SiteID, st.SiteName UNION --Bill Payer Summary (Sacramento) select qry2.siteid, st.sitename, sum(qry2.LineTot)/2 from ( select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS 'LineTot' from ( select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, l.StationID, sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID and ir.SiteID = l.SiteID where ih.SiteID in ('99') and l.StationID not in (35,36,37,38,39,40) and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID in (396,398,399,597) GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, ir.grossrate, ir.AgencyCommissionPct, l.StationID ) as qry1 group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth UNION select mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth, sum(mrc.InvNetRate) from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID in ('99') and mrc.StationID not in (35,36,37,38,39,40)
  • 47. 47 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID in (396,398,399,597) group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth ) AS QRY2 join dbo.tSite st on qry2.SiteID=st.SiteID GROUP BY qry2.siteid, st.SiteName UNION --Bill Payer Summary (Salt Lake City) select qry2.siteid, st.sitename, sum(qry2.LineTot)/2 from ( select qry1.siteid, qry1.invoiceid, qry1.invoicemonth, SUM(qry1.LineAmt) AS 'LineTot' from ( select ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, l.StationID, sum(ir.GrossRate) - (ir.grossrate * 0.15 * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType join Viero.tOrderLine_Current l on ir.OrderlineID = l.OrderlineID and ir.SiteID = l.SiteID where ih.SiteID in ('137') and l.StationID not in (73) and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID in (396,398,399,597) GROUP BY ir.SiteID, ih.Orderid, ir.invoiceID, ih.InvoiceMonth, ir.EnterpriseRevenueTypeID, ir.grossrate, ir.AgencyCommissionPct, l.StationID ) as qry1 group by qry1.SiteID, qry1.InvoiceID, qry1.InvoiceMonth UNION select mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth, sum(mrc.InvNetRate) from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID in ('137') and mrc.StationID not in (73) and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID in (396,398,399,597) group by mrc.SiteID, mrc.InvoiceNo, ih.InvoiceMonth ) AS QRY2
  • 48. 48 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) join dbo.tSite st on qry2.SiteID=st.SiteID GROUP BY qry2.siteid, st.SiteName ) AS QRY3 GROUP BY qry3.siteid, QRY3.SiteName order by QRY3.siteid ----------------------------------------------------------------------------- -------------------------- --Daily Load Tie Out Query Summary (DAX) with Sales Tax Included select qry1.ccarsite, SUM(qry1.AXAmt) as 'AXSum' from ( --Bill Payer Invoices from VIERO (Excluding Sacramento) select CIJ.CCARSITE, CIJ.INVOICEID, CIJ.CCARSOURCEINVOICENO, sum(cit.LINEAMOUNT) as 'AXAmt' from [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICETRANS cit (nolock) join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICEJOUR CIJ (NOLOCK) ON cit.INVOICEID=CIJ.INVOICEID where cij.ccarsite in ('43','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '137', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100', '102','110','118','120','122','134','151','155','157', '158','160','163','165','175','181','187','188','192', '194','243','247','258','268','275','277','294','306','312', '168','240','290' ) and cit.ITEMID in ('396','398','399','597') and cit.INVOICEDATE between @InvoiceMonth and @InvDateTo AND CIJ.CREATEDBY <> 'axtoo' GROUP BY CIJ.CCARSITE, CIJ.INVOICEID, CIJ.CCARSOURCEINVOICENO union all --Bill Payer Manual Invoices select b.CCARSITE, A.VOUCHER, a.ccarsourceorderno, SUM(amountcur) as 'AXAmt'
  • 49. 49 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[ccarCUSTTRANSdetail] a with (nolock) join [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTTABLE] b with (nolock) on a.accountnum = b.ACCOUNTNUM where TRANSDATE BETWEEN @InvoiceMonth AND @InvDateTo AND B.CCARSITE in ('43','99','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '137', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100', '102','110','118','120','122','134','151','155','157', '158','160','163','165','175','181','187','188','192', '194','243','247','258','268','275','277','294','306', '312', '168','240','290' ) and a.dimension2_ <> '97000' and ( (a.voucher BETWEEN 'MINV-000009845' AND 'MINV-000009846') or (a.voucher BETWEEN 'MINV-000009847' AND 'MINV-000009882') ) Group by b.ccarsite, A.VOUCHER, a.ccarsourceorderno union all --Bill Payer Invoices Sacramento SELECT QRY1.CCARSITE, QRY1.VOUCHER, CIJ.CCARSOURCEINVOICENO, SUM(QRY1.AXAMT) FROM ( select b.CCARSITE, A.VOUCHER, SUM(amountcur) as 'AXAmt' from [AXSQLCluster].[Prod_DynamicsAX].[dbo].[ccarCUSTTRANSdetail] a with (nolock) join [AXSQLCluster].[Prod_DynamicsAX].[dbo].[CUSTTABLE] b with (nolock) on a.accountnum = b.ACCOUNTNUM where TRANSDATE BETWEEN '20110801' and '20110831' AND B.CCARSITE in ('99') and a.dimension2_ <> '97000' AND A.ITEMID in ('396','398','399','597') group by b.CCARSITE, A.VOUCHER ) AS QRY1 join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICEJOUR CIJ (NOLOCK) ON QRY1.VOUCHER=CIJ.INVOICEID
  • 50. 50 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) GROUP BY QRY1.CCARSITE, QRY1.VOUCHER, CIJ.CCARSOURCEINVOICENO ) as qry1 group by qry1.ccarsite order by cast(qry1.ccarsite as int) Thiswill returnthe following results. Step 6(a): Copyand Paste the data intothe excel sheettitled“Invoice Tie”inthe tab labeled,“Tie Out- Bill Payer.” The firsthalf of the scriptwill be pastedintocolumnsA – C and the secondhalf of the script will be patedintocolumnsD& E. Nocolumnname in SQL scriptis knownasRadioDMAmt(columnC) and AXSum inSQL Script isknownas DAXAmount(columnE) inthe Excel file.
  • 51. 51 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Step 6(a)(1): Locate amountsin Tie Out-Bill Payerandcompare those toTie Outby Site. If the amounts closelymatch(i.e.site 12“Tie – Out Bill Payer”$51.02 & site 12 “Tie Out” $51.05) thenright “Bill Payer” underColumnG. Step 7: Runthe RadioDM and DAX Queries(Package InvoicingIdentification).sql . Makesure to change the dates. There are two locationsfordates towardsthe topof the script. Linkto script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth End ProceduresSQLScriptsDay2RadioDMand DAXQueries(Package InvoicingIdentification).sql Server: dwsqlclu8sql101 Database: Radio DM Authentication: SQL ServerAuthentication Log In: sqldev Password: whatareyoudoing??
  • 52. 52 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) DECLARE @INVDTFROM DATETIME DECLARE @INVDTTO DATETIME SET @INVDTFROM='20110801' SET @INVDTTO='20110831' -- This gives the list of Invoices associated with Package Charge Orders (Post Migration). Select qry2.siteid, qry2.stationid, qry2.INVID as 'VieroInv', qry2.BillToCust, daxcust.accountnum as 'DAXBillTo', qry2.AdvertiserID, daxadv.accountnum as 'DAXAdv', qry2.InvoiceDate, sum(qry2.NetRate) as 'InvoiceOutstanding' from ( Select TOC.SiteID, TIHC.InvoiceID as 'INVID', 'BillToCust' = case when tihc.agencyid=0 then tihc.advertiserid else TIHC.AgencyID end, tihc.advertiserid, DIM.NUM as 'StationID', ir.GrossRate, ir.AgencyCommissionPct, ir.GrossRate * (1 - ir.AgencyCommissionPct) as 'NetRate', TIHC.InvoiceDate from [RadioDM].[Viero].tOrder_Current TOC Join [RadioDM].[Viero].tInvoiceHeader_Current TIHC on TOC.SiteID = TIHC.SiteID and TOC.OrderID = TIHC.OrderID join [RadioDM].[Viero].tInvoiceRow IR on TIHC.siteid=IR.Siteid and TIHC.invoiceid=IR.invoiceid join [RadioDM].[Viero].torderline_current OL on IR.siteid=ol.siteid and ir.orderlineid=ol.orderlineid left join [RadioDM].[Viero].tStation sta on ol.SiteID=sta.SiteID and ol.stationid=sta.StationID join [RadioDM].[ERSP].tStation cl on sta.EnterpriseStationID=cl.EnterpriseStationID left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[DIMENSIONS] DIM (NOLOCK) on cl.Description COLLATE DATABASE_DEFAULT = LEFT(DIM.DESCRIPTION,7) COLLATE DATABASE_DEFAULT where TOC.PackageCharge = 1 and TIHC.InvoiceRowType = 1 UNION ALL Select TOC.SiteID, TIHC.InvoiceID as 'INVID', 'BillToCust' = case when tihc.agencyid=0 then tihc.advertiserid else TIHC.AgencyID end, tihc.advertiserid, DIM.NUM as 'StationID', ir.GrossRate, ir.AgencyCommissionPct, ir.GrossRate * (1 - ir.AgencyCommissionPct) as 'NetRate', TIHC.InvoiceDate from [RadioDM].[Viero].tOrder_Current TOC
  • 53. 53 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Join [RadioDM].[Viero].tInvoiceHeader_Current TIHC on TOC.SiteID = TIHC.SiteID and TOC.OrderID = TIHC.OrderID join [RadioDM].[Viero].tInvoiceRow IR on TIHC.siteid=IR.Siteid and TIHC.invoiceid=IR.invoiceid left join [RadioDM].[Viero].tMiscRevLine_Current OL on IR.siteid=ol.siteid and ir.MiscRevenueLineNo=ol.MiscRevLineNo left join [RadioDM].[Viero].tStation sta on ol.SiteID=sta.SiteID and ol.stationid=sta.StationID join [RadioDM].[ERSP].tStation cl on sta.EnterpriseStationID=cl.EnterpriseStationID left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[DIMENSIONS] DIM (NOLOCK) on cl.Description COLLATE DATABASE_DEFAULT = LEFT(DIM.DESCRIPTION,7) COLLATE DATABASE_DEFAULT where TOC.PackageCharge = 1 and TIHC.InvoiceRowType = 2 ) as qry2 LEFT join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxcust on qry2.BillToCust=daxcust.ccarsourcecustomerid and qry2.siteid=daxcust.CCARSITE LEFT join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxadv on qry2.AdvertiserID=daxadv.ccarsourcecustomerid and qry2.siteid=daxadv.CCARSITE where qry2.siteid in ('43','99','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '137', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100', '102','110','118','120','122','134','151','155','157', '159', '158','160','163','165','175','181','187','188','192', '194','243','247','258','268','275','277','294','306', '312', '168','240','290' ) and qry2.InvoiceDate between @INVDTFROM and @INVDTTO group by qry2.siteid, qry2.stationid, qry2.BillToCust, qry2.AdvertiserID, qry2.INVID, qry2.InvoiceDate,
  • 54. 54 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) daxcust.accountnum, daxadv.accountnum -- This gives the list of Invoices associated with Sub Invoicing (Post Migration). Select distinct qry1.siteid, qry1.StationID, qry1.SubInvoices, qry1.BillToCust, daxcust.accountnum as 'DAXBillTo', qry1.AdvertiserID, daxadv.accountnum as 'DAXAdv', qry1.BillDate, sum(qry1.GrossRate) as 'SumGross', sum(qry1.NetRate) as 'SumNet' from ( Select distinct TMRC.SiteID, TMRC.InvoiceNo as 'SubInvoices', 'BillToCust' = case when TMRC.agencyid=0 then TMRC.advertiserid else TMRC.AgencyID end, TMRC.advertiserid, DIM.NUM as 'StationID', TMRC.BillDate, TMRC.GrossRate, TMRC.AgencyCommissionPct, TMRC.NetRate from [RadioDM].[Viero].tMiscRevLine_Current TMRC left join [RadioDM].[Viero].tStation sta on TMRC.SiteID=sta.SiteID and TMRC.stationid=sta.StationID join [RadioDM].[ERSP].tStation cl on sta.EnterpriseStationID=cl.EnterpriseStationID left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[DIMENSIONS] DIM (NOLOCK) on cl.Description COLLATE DATABASE_DEFAULT = LEFT(DIM.DESCRIPTION,7) COLLATE DATABASE_DEFAULT where tmrc.PrimaryAdvertiser = 0 ) as qry1 left join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxcust on Qry1.BillToCust=daxcust.ccarsourcecustomerid and qry1.siteid=daxcust.CCARSITE LEFT join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].[CUSTTABLE] daxadv on qry1.AdvertiserID=daxadv.ccarsourcecustomerid and qry1.siteid=daxadv.CCARSITE where qry1.siteid in ('43','99','190','61','106', --Round 1 '57', '58', '70', '85', '89', '91', --Round 2 '93', '105', '112', '116', '121', '125', '139', '143', '170', '180', '215', '245', '248', '254', '272', '280', '288', '24', '25', '32', '34', '41', '46', '50', '52', --Round 3 '53', '55', '59', '63', '65', '67', '69', '71', '73', '76', '77', '92', '94', '95', '97', '101', '113', '114', '117', '119', '124', '126', '127', '128', '131', '132', '135', '146', '147', '150', '152', '156', '161', '162', '166', '167', '171', '173', '182', '183', '184', '185', '186', '193', '241', '242', '244', '249', '250', '252', '261', '270', '273', '279', '283', '284', '285', '289', '293', '318', '137', '12','14','16','17','19','26','27','28','35','37', --Round 4 '38','44','45','47','49','51','56','60','62','68', '74','75','80','81','82','86','87','88','90','100',
  • 55. 55 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) '102','110','118','120','122','134','151','155','157', '159', '158','160','163','165','175','181','187','188','192', '194','243','247','258','268','275','277','294','306', '312', '168','240','290' ) and qry1.BillDate between @INVDTFROM and @INVDTTO group by qry1.siteid, qry1.StationID, qry1.SubInvoices, qry1.BillToCust, daxcust.accountnum, qry1.AdvertiserID, daxadv.accountnum, qry1.BillDate Thiswill returnthe followingresults. Step 8: RunDAX Queries(Trade Invoice Identification).sql. Make sure to change the dates. There is one location for the date towards the middle ofthe script. YOUSHOULD RUN THIS AT LEAST 6 DAYS BEFORE MONTH-END BEGINS. IT IS ALSO SUGGESTEDTHAT YOURUN THIS EVERY FRIDAY. Linkto Script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth End ProceduresSQLScriptsDay2DAXQueries(Trade Invoice Identification) (3).sql
  • 56. 56 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Server: dwsqlclu8sql101 Database: Radio DM Authentication: SQL ServerAuthentication Log In: sqldev Password: whatareyoudoing?? --Manual Invoice Load Reversal Trade and E-Commerce Reversals select cij.CCArsite, cit.DIMENSION2_ AS 'BU', cij.ccarsourceinvoiceno, CTAG.CCARSOURCECUSTOMERID, cij.invoiceaccount AS 'AXBillTo', CTAD.CCARSOURCECUSTOMERID, cij.CCARADVERTISERNO AS 'AXAdvertiser', sum(cit.LINEAMOUNT) as 'InvAmt', cij.INVOICEID from [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICETRANS cit join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTINVOICEJOUR cij on cit.INVOICEID=cij.INVOICEID join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTTABLE CTAG ON cij.INVOICEACCOUNT=CTAG.ACCOUNTNUM join [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].CUSTTABLE CTAD ON cij.CCARADVERTISERNO=CTAD.ACCOUNTNUM where cit.ITEMID in ('390','396','598','599', '400', '401') and cit.INVOICEDATE between '08/01/2011' and '08/31/2011' and cit.LINEAMOUNT <> 0 group by cij.CCArsite, cit.DIMENSION2_, cij.ccarsourceinvoiceno, cij.invoiceaccount, CTAG.CCARSOURCECUSTOMERID, CTAD.CCARSOURCECUSTOMERID, cij.CCARADVERTISERNO, cij.INVOICEID
  • 57. 57 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) select SALESID, ITEMID, LINEPERCENT, LINEDISC, CCARAGENCYCOMMPCT from [AXSQLCLUSTER].[Prod_DynamicsAX].[dbo].SALESLINE where ITEMID in ('390','598','599', '400', '401','633') and LINEPERCENT = 0 Thiswill returnthe followingresults. Normally,noresultsare returned. However,incase something doesappear,thenproceedtostep 8(a). Step 8(a): If youhave any resultsfromstep8, run the following update script update dbo.SALESLINE set LINEPERCENT=100-CCARAGENCYCOMMPCT where ITEMID in ('390','598','599', '400', '401','633') and LINEPERCENT=0 --Rows Affected (83) Step 9: Run the RadioDM and DAX Queries(Manual InvoiceIdentification) v11a (draft). Makesure to change the dates. WORK ONFIXING THE PROBLEM. – THE SCRIPT RETURNS NULL AND IT SHOULD NOT. CONSULTWITH STEVE SAMPERI,BUT YOUMOST LIKELY WILL NEED TO DELETE THIS STEP – CHECK ON DAY 2 (10/4). USE THE SCRIPT THAT STEVE SAMPERI PROVIDED ON10/3. IF DOES NOT WORK,SKIP THIS STEP AND PROCEED TO STEP 10 AND USE THAT SCRIPT AND COMBINE IT WITH THIS. CHECK WITH SYLVIAFOWLER TO ENSURE SHE IS OKAY WITH THE NUMBER OF MANUALINVOICES.SHE MAY REQUEST THAT THIS BE RE-RUN.
  • 58. 58 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) Linkto Script: CCIFS1SATCommonFinancialInfoSystems&ReportingAXQueriesMonthendMonth End ProceduresSQLScriptsDay2RadioDMand DAXQueries(Manual Invoice Identification) v11a (draft).sql Server: dwsqlclu8sql101 Database: Radio DM Authentication: SQL ServerAuthentication Log In: sqldev Password: whatareyoudoing?? --Daily Load Tie Out Query Detail (Manual Invoices-in DM not in AX) declare @InvoiceMonth datetime declare @InvDateTo datetime set @InvoiceMonth='20110801' set @InvDateTo='20110831' --Site 44 Honolulu HI SELECT qry3.SiteID, LBU.DIMENSION2_, qry3.InvoiceID, BILLTO.accountnum AS 'AXBillto', BILLTO.ccarsourcecustomerid AS 'VIEROBillTo', ADV.accountnum as 'AXAdv', ADV.ccarsourcecustomerid as 'VIEROAdv', qry3.InvoiceMonth, qry3.DMAmt--, --CIJ.CCARSITE, CIJ.INVOICEID AS 'AXINV', CIJ.CCARSOURCEINVOICENO, CIJ.invoiceaccount as 'AXAcct', --CIJ.INVOICEAMOUNT, qry3.DMAmt-CIJ.INVOICEAMOUNT as 'Difference' from ( SELECT qry2.SiteID, qry2.InvoiceID, qry2.InvoiceMonth,
  • 59. 59 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) SUM(qry2.DMAmt) as 'DMAmt' FROM ( select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '44' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '44' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '44' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '44' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000'
  • 60. 60 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '44' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth UNION --Site 51 Phoenix AZ select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '51' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '51' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1
  • 61. 61 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '51' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '51' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '51' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth UNION --Site 68 Sarasota FL select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID
  • 62. 62 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '68' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '68' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '68' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '68' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '68' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0
  • 63. 63 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth UNION --Site 81 Orlando FL select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '81' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '81' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '81' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock)
  • 64. 64 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '81' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '81' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth UNION --Site 110 Albuquerque NM select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth, SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '110' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc
  • 65. 65 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '110' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '110' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '110' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate from Viero.tMiscRevLine_Current mrc join [RadioDM].[Viero].tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '110' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth ) group by SiteID, InvoiceID, InvoiceMonth UNION --Site 268 Farmington NM select qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth,
  • 66. 66 ProceduresforMonth-EndClose Day2 & 3| ClearChannel rev.091911(sbz) SUM(qry1.LineAmt) as 'DMAmt' from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from Viero.tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '268' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all --Misc Invoice Rows select mrc.SiteID, mrc.InvoiceNo, ih.invoicemonth, mrc.InvNetRate as 'DMAmt' from Viero.tMiscRevLine_Current mrc join Viero.tInvoiceHeader_Current ih (nolock) on mrc.SiteID=ih.SiteID and mrc.InvoiceNo=ih.InvoiceID where ih.SiteID = '268' and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 and ih.InvoiceRowType=2 and EnterpriseMiscRevTypeID not in (390,396,598,599,398,399,400,401,633) ) as qry1 group by qry1.siteid, qry1.invoiceid, qry1.InvoiceMonth UNION --Radio DM Query for Daily Load Tax Calculation select SiteID, InvoiceID, InvoiceMonth, sum(Tax) as 'SumTax' from viero.tinvoiceheader_current where siteid = '268' and invoiceid in ( select qry1.invoiceid from ( select ir.SiteID, ir.invoiceID, ih.InvoiceMonth, sum(ir.GrossRate) - (ir.grossrate * ir.AgencyCommissionPct * count(ir.OrderLineNo)) as LineAmt from [RadioDM].[Viero].tInvoiceRow ir (nolock) join viero.tInvoiceHeader_Current ih (nolock) on ir.SiteID=ih.SiteID and ir.InvoiceID=ih.InvoiceID and ir.InvoiceRowType=ih.InvoiceRowType where ih.SiteID = '268' and ih.InvoiceRowType=1 and ir.Autofill=0 and ih.InvoiceMonth = @InvoiceMonth and InvoiceDeleted = 0 --and ih.InvoiceDateEntered < '2010-09-27 00:00:00.000' and ir.EnterpriseRevenueTypeID not in (390,396,598,599,398,399,400,401,633) GROUP BY ir.SiteID, ir.invoiceID, ir.grossrate, ir.AgencyCommissionPct, ih.invoicemonth union all