I'm converting an old database to an Access program and there are a bunch of SQL queries that need to be imported into Access. I'm no SQL expert but I can create simple queries. The old program used an SQL server and here is an example SQL query it used:
There are a bunch of SQL files such as this and they are lengthy. My first question is, what is the best way to go about converting this into my new Access program?
Also, I think the "CREATE TABLE" line in SQL server cannot be used in Access SQL, so is there any way to create temporary tables and then delete them in a query or should I just have a table that is emptied every time the query is run?
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Sproc_GenerateEmployerSetRateInvoices]
@sQuery varchar(1000),
@CurrentDate datetime,
@AccountingPeriodID int
AS
BEGIN TRY
BEGIN TRAN
Begin
Declare @BatchID int
Insert Into TAC_InvoiceBatch(RegenerationBatch)
values(2)
set @BatchID = Scope_Identity()
End
BEGIN
CREATE TABLE #InvoiceDetailTmp (
InvoiceDetailIDTmp int not null Identity(1,1),
GenerationDateID int null,
EmployerID int,
PlanID int,
EmployeeID int,
GenerationDate datetime,
PeriodtoBillDate datetime,
Rate money,
AccountingPeriodID int,
DateActive datetime,
BillingCycleID int,
ContractID int,
PlanBenWWaitID int,
SetRateAtEmployee int,
PlanRateID Int,
InitialFee int,
GroupID varchar(255)
)
CREATE TABLE [#InvoiceTmp](
[InvoiceIDTmp] [int] IDENTITY(1,1) NOT NULL,
[InvoiceBatchID] [int] NULL,
[EmployerID] [int] NULL,
[InvoiceBalance] [int] NULL,
[GenerationDate] [datetime] NULL,
[Balance] [money] NULL,
[PaidAmount] [money] NULL,
[TotalAmount] [money] NULL,
[DueDate] [datetime] NULL,
[UpdateDate] [datetime] NULL,
[AccountingPeriodID] [int] NULL,
[BillingCycleID] [int] NULL
)
END
BEGIN
BEGIN
--This section Creates all detail Invoice Items
Insert Into #InvoiceDetailTmp(GenerationDateID,EmployerID,PlanID,EmployeeID,GenerationDate,PeriodToBillDate,Rate,DateActive,ContractID,PlanBenWWaitID,BillingCycleID,SetRateAtEmployee,PlanRateID,InitialFee)
select a.GenerationDateID,
c.EmployerID,
b.PlanID,
e.EmployeeID,
a.GenerationDate,
dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) as PeriodToBill,
c.Rate,
dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) as DateActive,
f.ContractID,
f.PlanBenWWaitID,
d.BillingCycleID,
d.SetRateAtEmployee,
c.EmployerPlanRateID,
2
From TAC_GenerationDate a inner join TMI_Plan b
on a.BenefitTypeID = b.BenefitTypeID inner join
tmi_EmployerPlanrate c on b.PlanID = c.PlanID inner join
TMI_BenefitType d on a.BenefitTypeID = d.BenefitTypeID inner join
TMI_EmployeePlan e on c.PlanID = e.PlanID and e.EmployerID = c.EmployerID inner join
TMI_EmployerPlanBenWWait f on c.ContractID = f.ContractID and b.BenefitTypeID = f.BenefitTypeID inner join
TMI_Employer g on c.EmployerID = g.EmployerID inner join TMI_Provider h
on g.ProvID = h.ProvID inner join TMI_ProviderPlan i on h.ProvID = i.ProvID and e.PlanID = i.planID
inner join TMI_ProviderBenefitType j on h.ProvID = j.ProvID and d.BenefitTypeID = j.BenefitTypeID
where d.SetRateAtEmployee = 2 and c.EmployerPlanRateID =
(Select Top 1 a1.EmployerPlanRateID From TMI_EmployerPlanRate a1 where a1.EffectiveDate <= dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) and a1.EmployerID = c.EmployerID and a1.PlanID = c.PlanID order by a1.EffectiveDate desc)
and d.BillingTypeID = 1
and (
( --BIll by daterange employer = 2 bill by daterange employee = 2
d.BillByDateRangeEmployer = 2 and d.BillByDateRangeEmployee =2
and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employer = 1 BypassStatus = 2
d.BillByDateRangeEmployer = 1 and d.BypassStatus =2
and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between f.startdate and f.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employee = 1 BypassStatus = 2
d.BillByDateRangeEmployee = 1 and d.BypassStatus =2
and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between e.startdate and e.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employer = 1 BypassStatus = 1
d.BillByDateRangeEmployer = 1 and d.BypassStatus =1
--and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between f.startdate and f.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employee = 1 BypassStatus = 1
d.BillByDateRangeEmployee = 1 and d.BypassStatus =1
--and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between e.startdate and e.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
) -- Close out entire section
union all
select a.GenerationDateID,
c.EmployerID,
b.PlanID,
e.EmployeeID,
a.GenerationDate,
dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) as PeriodToBill,
c.Rate,
dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) as DateActive,
f.ContractID,
f.PlanBenWWaitID,
d.BillingCycleID,
d.SetRateAtEmployee,
c.EmployeePlanRateID,
2
From TAC_GenerationDate a inner join TMI_Plan b
on a.BenefitTypeID = b.BenefitTypeID inner join
tmi_EmployeePlanrate c on b.PlanID = c.PlanID inner join
TMI_BenefitType d on a.BenefitTypeID = d.BenefitTypeID inner join
TMI_EmployeePlan e on c.PlanID = e.PlanID and e.EmployerID = c.EmployerID inner join
TMI_EmployerPlanBenWWait f on f.ContractID = (Select Top 1 aa.ContractID from TMI_EmployerContract aa inner join
TMI_EmployerPlanBenWWait ab on aa.ContractID = ab.ContractID
where aa.ContractStartdate <= c.EffectiveDate and ab.BenefitTypeID = a.BenefitTypeID and ab.EmployerID = c.EmployerID order by aa.ContractStartDate Desc)
and b.BenefitTypeID = f.BenefitTypeID inner join
TMI_Employer g on c.EmployerID = g.EmployerID inner join TMI_Provider h
on g.ProvID = h.ProvID inner join TMI_ProviderPlan i on h.ProvID = i.ProvID and e.PlanID = i.planID
inner join TMI_ProviderBenefitType j on h.ProvID = j.ProvID and d.BenefitTypeID = j.BenefitTypeID
where d.SetRateAtEmployee = 1 and c.EmployeePlanRateID =
(Select Top 1 a1.EmployeePlanRateID From TMI_EmployeePlanRate a1 where a1.EffectiveDate <= dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) and a1.EmployeeID = c.EmployeeID and a1.PlanID = c.PlanID order by a1.EffectiveDate desc)
and d.BillingTypeID = 1
and (
( --BIll by daterange employer = 2 bill by daterange employee = 2
d.BillByDateRangeEmployer = 2 and d.BillByDateRangeEmployee =2
and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employer = 1 BypassStatus = 2
d.BillByDateRangeEmployer = 1 and d.BypassStatus =2
and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between f.startdate and f.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employee = 1 BypassStatus = 2
d.BillByDateRangeEmployee = 1 and d.BypassStatus =2
and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between e.startdate and e.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employer = 1 BypassStatus = 1
d.BillByDateRangeEmployer = 1 and d.BypassStatus =1
--and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between f.startdate and f.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
or
( --BIll by daterange employee = 1 BypassStatus = 1
d.BillByDateRangeEmployee = 1 and d.BypassStatus =1
--and not dbo.EmployeeActiveinPeriod(e.EmployeeID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID),d.BillingCycleID) is null
and not dbo.EmployerActive(c.EmployerID,dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)) is null
and h.ProvStatusID = 1
and i.statusid = 1
and c.statusID = 1
and j.statusID = 1
and dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID) between e.startdate and e.Enddate
and((f.BillCurrent = 1 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+0, 0)))
or
(f.BillCurrent = 2 and
(dbo.AdjustDate(d.BillingCycleID,d.PeriodtoBill,a.GenerationDate,d.BenefitTypeID)>= DATEADD(mm, DATEDIFF(mm, 0, dateAdd(Month,f.WaitingPeriod,(select top 1 zz.EffectiveDate from TMI_EmployeeStatus zz where zz.EmployeeID = e.EmployeeID and zz.EstatusID =1 and zz.StatusID = 1 order by zz.effectiveDate asc )))+1, 0))))
)
) -- Close out entire section
order by e.EmployeeID,b.PlanID,a.generationDate
END
BEGIN
--THIS Section Creates the Invoice Item
select a.*,c.fee from
#InvoiceDetailTmp a left join TAR_InvoiceDetail b
on a.EmployeeID = b.EmployeeID and b.PlanID = b.PlanID
inner join Tmi_EmployerPlanRate c on a.PlanRateID = c.EmployerPlanRateID
where a.SetRateAtEmployee = 2 and b.EmployeeID is null and b.PlanID is null
union
select a.*,c.fee from
#InvoiceDetailTmp a left join TAR_InvoiceDetail b
on a.EmployeeID = b.EmployeeID and b.PlanID = b.PlanID
inner join Tmi_EmployeePlanRate c on a.PlanRateID = c.EmployeePlanRateID
where a.SetRateAtEmployee = 1 and b.EmployeeID is null and b.PlanID is null
END
END
Commit Tran
/*Make sure to update TAC_GeneratedDates.Generated from 2 to 1*/
return 1
END TRY
BEGIN CATCH
IF (XACT_STATE()) <> 0 ROLLBACK
DECLARE @ErrMsg varchar(4000), @ErrSeverity int
set @ErrMsg = ERROR_MESSAGE()
Set @ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, @ErrSeverity)
return 0
END CATCH
/*select * from TAC_GenerationDate
Select ROW_NUMBER() OVER (ORDER BY EmployeePlanID) as Rownum,EmployeePlanID from TMI_EmployeePlan
Select * from TMI_EmployeeStatus
select * from TMI_EmployerPlanRate
select * from TMI_BenefitType
select * from TMI_EmployerPlanRate
select * from TMI_Plan where PlanID in (106,108)
update TMI_EmployeeStatus
set EffectiveDate = dateadd(month,-5,getdate())
where EffectiveDate = '07/31/06'
declare @Var int
set @Var = 3
Select CASE @Var
WHEN 1 THEN DATEADD(month, 1, '01/01/2005')
WHEN 2 THEN DATEADD(week, 1, '01/01/2005')
WHEN 3 THEN DATEADD(week, 1 * 2, '01/01/2005')
WHEN 4 THEN DATEADD(quarter,1, '01/01/2005')
WHEN 5 THEN DATEADD(quarter, 1 * 2, '01/01/2005')
WHEN 6 THEN DATEADD(year, 1, '01/01/2005')
END
Declare @Tbl Table
(
i int,
j int IDENTITY(1,1)
)
Insert @Tbl
Select 3333 Union All
Select 3333 Union All
Select 1234 Union All
Select 1309 Union All
Select 1309 Union All
Select 1309 Union All
Select 1309 union all
Select 1309 union all
Select 1309 union all
Select 3332 Union All
Select 3332 Union All
Select 3332
Select (Select Count(1) From @Tbl t1 Where t1.i= t.i and t1.j<=t.j ) , i From @Tbl t
*/
There are a bunch of SQL files such as this and they are lengthy. My first question is, what is the best way to go about converting this into my new Access program?
Also, I think the "CREATE TABLE" line in SQL server cannot be used in Access SQL, so is there any way to create temporary tables and then delete them in a query or should I just have a table that is emptied every time the query is run?