We help IT Professionals succeed at work.
Get Started

Microsoft, SQL, 2005 - Query Assistance

283 Views
Last Modified: 2008-03-06
Server: Msg 8134, Level 16, State 1, Line 228
Divide by zero error encountered.
The statement has been terminated.

Ive never encountered this one before .... can anyone assist me please?
SET NOCOUNT ON
declare @db varchar(50),
    @startdate datetime,
	@enddate datetime,
    @counterdate datetime,
    @datevar datetime,
    @agingdate varchar(20),
    @counter int
 
create table #output
(
    ProviderName varchar(100),
    doctorfacilityID int,    
    ARBalance money,
    AR120 float,    
    DaysInAR float,
    Charges money,
    Payments money,
    Adjustments money,
    TotalVisits int,
    NewVisits int,
    CollectedAvg float,
    NetCollectedAvg float,
    [Month] int,
    [Year] int
)
 
 
CREATE TABLE #Aging(	PatientVisitId int NULL,
			InsDeposit money NULL,
			PatDeposit money NULL,
			InsBalance0 money NULL,
			PatBalance0 money NULL,
			InsBalance30 money NULL,
			PatBalance30 money NULL,
			InsBalance60 money NULL,
			PatBalance60 money NULL,
			InsBalance90 money NULL,
			PatBalance90 money NULL,
			InsBalance120 money NULL,
			PatBalance120 money NULL,
			InsBalance money NULL,
			PatBalance money NULL
 )
 
create table #temp
(
    ProviderName varchar(100),
    doctorfacilityID int,
    Charges90    money,
    [Month] int,
    [Year] int
)
 
create table #temp2
 ( 
    ProviderName varchar(100),
    DoctorFacilityID int,
    ARBalance money,
    AR120 float,
    [Month] int,
    [Year] int
)
 
set @datevar  = ISNULL('11/01/2007','1/1/1900') 
set @counter =1
set @DB = DB_Name()
set @startdate = dateadd(day,-1,(dateadd(month,1,@datevar)))-- puts us at end of current month
set @startdate = dateadd(month, -11,@startdate) -- sets u 12 months from end of last month of entry
 
 
--Create table of aging values for the last 12 months
--start our while loop
while @counter <= 12
begin
    
    set @enddate = dateadd(month,(@counter), @startdate) 
    set @agingdate = convert(varchar(12),dateadd(d,-1,(cast(month(@enddate)as varchar(2))+'/1/'+cast(year(@enddate)as varchar(4)))),101)
 
    INSERT INTO #Aging exec master..mbcxp_AgingVisit70 @DB, @agingdate, 1, 0, NULL, NULL, NULL
 
    INSERT INTO #temp2 (Providername, doctorfacilityID, ARBalance, AR120, [Month], [Year])
    select dr.listname as ProviderName,
        dr.doctorfacilityID,
        sum(InsBalance)+ SUM(patbalance) as ARBalance,
        ((sum(ISNULL(InsBalance120,0))+ SUM(ISNULL(patbalance120,0))) / (Sum(isnull(patbalance,0)) + sum(isnull(insbalance,0))))*100 as AR120,
        DatePart(month,@agingdate) AS [Month], 
        DatePart(year,@agingdate) AS [Year]         
    from #aging a
        inner join patientvisit pv on a.patientvisitID = pv.patientvisitID
        inner join doctorfacility dr on pv.doctorID = dr.doctorfacilityID
        LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID
       	AND  --Filter on Carrier
    	(
    	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
    	(NULL IS NULL)
    	)
    	AND  --Filter on company
    	(
	    (NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
    	(NULL IS NULL)
	    )
       AND  --Filter on facility
	    (
    	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	    ('637' IS NULL)
    	)
        AND  --Filter on Financial Class
    	(
	    (NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
    	(NULL IS NULL)
	    )
        AND --Filter on Ins Group
    	(
   	    (NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
    	(NULL IS NULL)
	    )
        AND  --Filter on Provider
	    (
    	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
    	(NULL IS NULL)
	    )
    group by dr.listname, dr.doctorfacilityID
 
    truncate table #aging    
    set @counter = @counter+1
 
end -- while loop aging
 
---Create table of avg daily charge for previous 90 days of past 12 months
--start our while loop
set @counterdate = dateadd(day,-1,(dateadd(month,2,@datevar)))--gets us to end of last day entry month for month after...long story
set @counter = 0
while @counter < 12
begin
    set @enddate = dateadd(month,(0-@counter), @counterdate) 
-- need to take enddate month +/1/+ year, the sutract 1 day to get to last day of month
    set @enddate = convert(varchar(12),dateadd(d,-1,(cast(month(@enddate)as varchar(2))+'/1/'+cast(year(@enddate)as varchar(4)))),101)
    set @startdate =dateadd(month, -2,@enddate)
    set @startdate= cast(month(@startdate) as varchar(2))+'/1/'+cast(year(@startdate)as varchar(4))
 
    insert into #temp (ProviderName, doctorfacilityID, charges90, [Month], [Year])
    SELECT --pv.PatientVisitId, 
        dr.Listname AS ProviderName, 
        dr.doctorfacilityID,
        SUM(pvp.TotalFee) AS Charges90, 
    --    SUM(pvpa.insPayment + pvpa.patPayment + pvpa.insAdjustment + pvpa.patAdjustment)/SUM(pvp.TotalFee)*100 as CollectedAvg,
        DatePart(month,@enddate) AS [Month], 
        DatePart(year,@enddate) AS [Year] 
    --    cast(cast(DatePart(month,b.entry)as Varchar(2))+'/1/'+ cast(DatePart(year,b.entry)as varchar(4))AS DATETIME) AS MonthYear
    FROM PatientVisit pv
        INNER JOIN DoctorFacility dr ON pv.DoctorId = dr.DoctorFacilityId 
        INNER JOIN PatientVisitProcs pvp ON pv.PatientVisitId = pvp.PatientVisitId 
        INNER JOIN PatientVisitProcsAgg pvpa on pvp.patientvisitprocsID = pvpa.patientvisitprocsID
        INNER JOIN Batch b ON pvp.BatchId = b.BatchId
        LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID
    WHERE pvp.TotalFee<>0 
        AND b.Entry>=@startDate
        And b.Entry<dateadd(d,1,@endDate)
        AND  --Filter on Carrier
    	(
    	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
    	(NULL IS NULL)
    	)
        AND  --Filter on company
    	(
                (NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
    	(NULL IS NULL)
	    )
        AND  --Filter on facility
	    (
    	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	    ('637' IS NULL)
    	)
        AND  --Filter on Financial Class
    	(
	    (NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
    	(NULL IS NULL)
	    )
        AND --Filter on Ins Group
    	(
   	    (NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
    	(NULL IS NULL)
	    )
        AND  --Filter on Provider
	    (
    	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
    	(NULL IS NULL)
	    )
        group by dr.listname, dr.doctorfacilityID--, DatePart(month,@enddate), DatePart(year,@enddate)
    
    set @counter = @counter +1
 
end --whil loop
 
update #temp
set charges90 = charges90/90
where charges90 is not null
 
--insert AR pecentage in 120+
insert into #output (providername, doctorfacilityID, AR120, [Month], [Year])
select t2.providername, 
    t2.doctorfacilityID,
    t2.AR120,
    t2.month, 
    t2.year
from #temp t1
    inner join #temp2 t2 on t1.doctorfacilityID = t2.doctorfacilityID and t1.month = t2.month
 
--insert days in AR
insert into #output (providername, doctorfacilityID, DaysInAR, [Month], [Year])
select t2.providername, 
    t2.doctorfacilityID,
    case t1.charges90
        when 0 then 0
        else t2.arbalance/t1.charges90
    end as DaysInAR,
    t2.month, 
    t2.year
from #temp t1
    inner join #temp2 t2 on t1.doctorfacilityID = t2.doctorfacilityID and t1.month = t2.month
 
------------------------------------  Collection %    --------------------------
--reset our date ranges
set @enddate = dateadd(month,1,@datevar)
set @startdate = dateadd(month,-11,@datevar)
 
insert into #output (ProviderName, DoctorfacilityID, charges, collectedAvg, [Month], [Year])
SELECT --pv.PatientVisitId, 
    dr.Listname AS Providername,
    dr.doctorfacilityID,
    SUM(pvp.TotalFee) AS Charges, 
    ((SUM(pvpa.insPayment) + sum(pvpa.patPayment) + sum(pvpa.insAdjustment) + sum(pvpa.patAdjustment))/SUM(pvp.TotalFee))*100 as CollectedAvg,
    DatePart(month,b.entry) AS [Month], 
    DatePart(year,b.entry) AS [Year] 
FROM PatientVisit pv
    INNER JOIN DoctorFacility dr ON pv.DoctorId = dr.DoctorFacilityId 
    left JOIN PatientVisitProcs pvp ON pv.PatientVisitId = pvp.PatientVisitId 
    INNER JOIN PatientVisitProcsAgg pvpa on pvp.patientvisitprocsID = pvpa.patientvisitprocsID
    INNER JOIN Batch b ON pvp.BatchId = b.BatchId
    LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID
WHERE pvp.TotalFee<>0 
    AND b.Entry>=@StartDate
    And b.Entry<@endDate
    AND ISNULL(pvp.Voided,0) = 0
   	AND  --Filter on Carrier
	(
	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on company
	(
	(NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
   AND  --Filter on facility
	(
	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	('637' IS NULL)
	)
    AND  --Filter on Financial Class
	(
	(NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
	(NULL IS NULL)
	)
        AND --Filter on Ins Group
	(
	(NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
	(NULL IS NULL)
	)
    AND  --Filter on Provider
	(
	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
group by dr.listname, dr.doctorfacilityID, DatePart(month,b.entry), DatePart(year,b.entry)
 
-------------------------------- Net collection % ---------------------------------------
insert into #output (ProviderName, doctorfacilityID, netcollectedAvg, [Month], [Year])
SELECT dr.Listname AS Doctor, 
    dr.doctorfacilityID,
    (((SUM(pvpa.insPayment) + SUM(pvpa.patPayment))/(SUM(pvpa.insPayment) + sum(pvpa.patPayment)+SUM(td.amount)))) *100 as NetCollectedAvg,
    DatePart(month,b.entry) AS [Month], 
    DatePart(year,b.entry) AS [Year] 
FROM PatientVisit pv
    INNER JOIN DoctorFacility dr ON pv.DoctorId = dr.DoctorFacilityId 
    INNER JOIN PatientVisitProcs pvp ON pv.PatientVisitId = pvp.PatientVisitId 
    INNER JOIN PatientVisitProcsAgg pvpa on pvp.patientvisitprocsID = pvpa.patientvisitprocsID
    LEFT JOIN transactiondistributions td on pvp.patientvisitprocsID = td.patientvisitprocsID
    LEFT JOIN transactions t on td.transactionsID = t.transactionsID
    inner join (Select * from medlists where tablename = 'adjustmenttypes' and functionname = 'N') act on t.actiontypeMID = act.medlistsID
    INNER JOIN Batch b ON pvp.BatchId = b.BatchId
    LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID
WHERE pvp.TotalFee<>0 
    AND b.Entry>=@StartDate
    And b.Entry<@endDate
    AND ISNULL(pvp.Voided,0) = 0
   	AND  --Filter on Carrier
	(
	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on company
	(
	(NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
   AND  --Filter on facility
	(
	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	('637' IS NULL)
	)
    AND  --Filter on Financial Class
	(
	(NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
	(NULL IS NULL)
	)
        AND --Filter on Ins Group
	(
	(NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
	(NULL IS NULL)
	)
    AND  --Filter on Provider
	(
	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
group by dr.listname, dr.doctorfacilityID, DatePart(month,b.entry), DatePart(year,b.entry)
 
-----------------           Payments by DOE           ------------------------------
 
INSERT INTO #output (ProviderName, doctorfacilityID, Payments, [Month], [Year])
SELECT 
    dr.ListName AS ProviderName, 
    dr.doctorfacilityID,
    vt.Payments,
    DATEPART(MONTH,b.entry) AS [Month], 
    DATEPART(YEAR,b.entry) AS [Year]
FROM PaymentMethod pm
    INNER JOIN VisitTransactions vt ON pm.PaymentMethodId = vt.PaymentMethodId 
    INNER JOIN Batch b ON pm.BatchId = b.BatchId 
    INNER JOIN PatientVisit pv ON pv.PatientVisitid = vt.PatientVisitId
    INNER JOIN DoctorFacility dr ON pv.DoctorId = dr.DoctorFacilityId 
    INNER JOIN PatientProfile pp ON pv.PatientProfileId = pp.PatientProfileId
    LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID    
WHERE b.Entry>=@StartDate
    And b.Entry<@endDate
    AND vt.Payments<>0
   	AND  --Filter on Carrier
	(
	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on company
	(
	(NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
   AND  --Filter on facility
	(
	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	('637' IS NULL)
	)
    AND  --Filter on Financial Class
	(
	(NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
	(NULL IS NULL)
	)
        AND --Filter on Ins Group
	(
	(NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
	(NULL IS NULL)
	)
    AND  --Filter on Provider
	(
	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
 
---------------------------                Adjustments by DOE     ---------------------------
 
INSERT INTO #output (ProviderName, doctorfacilityID, adjustments, [Month], [Year])
SELECT 
    dr.ListName AS Providername, 
    dr.doctorfacilityID,
    vt.Adjustments, 
    DATEPART(MONTH,b.entry) AS [Month], 
    DATEPART(YEAR,b.entry) AS [Year]
FROM PaymentMethod pm 
    INNER JOIN VisitTransactions vt ON pm.PaymentMethodId = vt.PaymentMethodId 
    INNER JOIN Batch b ON pm.BatchId = b.BatchId 
    INNER JOIN PatientVisit pv ON vt.PatientVisitid = pv.PatientVisitId
    INNER JOIN DoctorFacility dr ON pv.DoctorId = dr.DoctorFacilityId 
    INNER JOIN PatientProfile pp ON pv.PatientProfileId = pp.PatientProfileId
    LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID
WHERE b.Entry>=@StartDate
    And b.Entry<@endDate
    AND vt.Adjustments<>0
   	AND  --Filter on Carrier
	(
	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on company
	(
	(NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
   AND  --Filter on facility
	(
	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	('637' IS NULL)
	)
    AND  --Filter on Financial Class
	(
	(NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
	(NULL IS NULL)
	)
        AND --Filter on Ins Group
	(
	(NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
	(NULL IS NULL)
	)
    AND  --Filter on Provider
	(
	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
 
----------------------------             Total Visits by DOE  -----------------------------------------
INSERT INTO #output (ProviderName, doctorfacilityID, TotalVisits, [Month], [Year])
select 
    dr.Listname AS Providername,
    dr.doctorfacilityID,
   ----- count(distinct pv.patientvisitID) as TotalVisits,
    count(pvp.code) as TotalVisits,
    DatePart(month,b.entry) as [Month], 
    DatePart(year,b.entry) AS [Year]
from patientvisit pv
    inner join patientvisitprocs pvp on pv.patientvisitID = pvp.patientvisitID
    inner join batch b on pvp.batchID = b.batchID
    inner join doctorfacility dr on pv.doctorID = dr.doctorfacilityID
    LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID
where b.Entry>=@StartDate
    And b.Entry<@endDate
    and isnull(pvp.voided,0) = 0
   	AND  --Filter on Carrier
	(
	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on company
	(
	(NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
   AND  --Filter on facility
	(
	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	('637' IS NULL)
	)
    AND  --Filter on Financial Class
	(
	(NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
	(NULL IS NULL)
	)
        AND --Filter on Ins Group
	(
	(NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
	(NULL IS NULL)
	)
    AND  --Filter on Provider
	(
	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
group by dr.listname, dr.doctorfacilityID, DatePart(month,b.entry), DatePart(year,b.entry)
 
----------------------------             NEW Visits by DOE  -----------------------------------------
INSERT INTO #output (ProviderName, doctorfacilityID, NewVisits, [Month], [Year])
select distinct 
    dr.Listname AS Providername,
    dr.doctorfacilityID,
    count(distinct pv.patientvisitID) as NewVisits,
    DatePart(month,b.entry) as [Month], 
    DatePart(year,b.entry) AS [Year]
from patientvisit pv
    inner join patientvisitprocs pvp on pv.patientvisitID = pvp.patientvisitID
    inner join batch b on pvp.batchID = b.batchID
    inner join doctorfacility dr on pv.doctorID = dr.doctorfacilityID
    LEFT JOIN insurancecarriers ic ON pv.primaryinsurancecarriersID = ic.insurancecarriersID
where b.Entry>=@StartDate
    And b.Entry<@endDate
    and isnull(pvp.voided,0) = 0
    AND (
           (pvp.CPTCode>='99201' And pvp.CPTCode<='99205')
        OR (pvp.CPTCode>='99381' AND pvp.CPTCode<='99387') 
        OR (pvp.CPTCode>='99241' And pvp.CPTCode<='99245') 
        OR (pvp.CPTCode='NEWOB')
        OR (pvp.CPTCode='92002')        --- Opthalmology codes 
        OR (pvp.CPTCode='92004')
        OR (pvp.CPTCode='92012')
        OR (pvp.CPTCode='92014')
        ) 
   	AND  --Filter on Carrier
	(
	(NULL IS NOT NULL AND pv.primaryinsurancecarriersID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on company
	(
	(NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
   AND  --Filter on facility
	(
	('637' IS NOT NULL AND pv.FacilityID IN (637)) OR
	('637' IS NULL)
	)
    AND  --Filter on Financial Class
	(
	(NULL IS NOT NULL AND pv.FinancialClassMID IN (NULL)) OR
	(NULL IS NULL)
	)
        AND --Filter on Ins Group
	(
	(NULL IS NOT NULL AND ic.insuranceGroupID IN (NULL)) OR
	(NULL IS NULL)
	)
    AND  --Filter on Provider
	(
	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
group by dr.listname, dr.doctorfacilityID, DatePart(month,b.entry), DatePart(year,b.entry)
 
--need to make sure every doc has a row for every month/year combo in the specified date range 
--in order to properly format the crystal reports crosstab.  Takes a table of distinct docs and
--a table of the distinct month/year combos in the selected date range and inserts the results 
--of a cross join of the two.  
 
DECLARE @countermonth DATETIME
 
CREATE TABLE #tempdates
(
    monthyear DATETIME
)
 
SET @countermonth = @startdate
WHILE @countermonth < @enddate
BEGIN 
    INSERT INTO #tempdates (monthyear)
    SELECT @countermonth
 
    SET @countermonth = dateadd(month,1,@countermonth)
END -- while loop
 
SELECT DISTINCT Providername, doctorfacilityID
INTO #tempdocs
FROM #output
 
 
INSERT INTO #output (ProviderName, DoctorfacilityID, ARBalance, AR120, DaysInAR, Charges, CollectedAvg, NetCollectedAvg, [Month], [Year])
SELECT  
    t.providername as ProviderName,  
    t.doctorfacilityID,
    0 as ARBalance,
    0 as AR120,
    0 as DaysInAR,
    0 as charges,
    0 as CollectedAVg,
    0 as NetCollectedAvg,
    DatePart(month,td.monthyear), 
    DatePart(year,td.monthyear)
FROM #tempdocs t
    CROSS JOIN #tempdates td
 
select ProviderName, DoctorFacilityID, 
    ISNULL(ARBalance,0) as ARBalance, 
    ISNULL(AR120,0) as AR120,
    ISNULL(DaysInAR,0) as DaysInAR,
    ISNULL(Charges,0) as Charges,
    ISNULL(Payments,0) as Payments,
    ISNULL(Adjustments,0) as Adjustments,
    ISNULL(TotalVisits,0) as TotalVisits,
    ISNULL(NewVisits,0) as NewVisits,
    ISNULL(CollectedAvg,0) as CollectedAvg,
    ISNULL(NetcollectedAvg,0) as NetCollectedAvg,
    [Month], 
    [Year],
    cast(cast([Month] as Varchar(2))+'/1/'+ cast([Year]as varchar(4))AS DATETIME) AS MonthYear
 
--into data
--drop table data
from #output
 
--select *
--from #temp2
 
drop table #temp, #temp2, #aging, #output, #tempdocs, #tempdates

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE