Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure to return results

Author  Topic 

anaylor01
Starting Member

28 Posts

Posted - 2008-09-24 : 15:48:01
I need this procedure to return the results of the last query


ALTER proc spQ_GetASCBillingRateIDs2

(
@ScheduleID CHAR(15),
@startdate smalldatetime,
@enddate smalldatetime
)

as

set nocount on


exec sp_CreateTblTmpGroup

insert into tbltmpgroup
SELECT DISTINCT
case when pd.billparent = 'N' then org.eligibleorgid
else isnull(af.parentid, org.eligibleorgid) end as billorgid,
pd.individualbill , pd.cobrabill, pd.billparent,
org.eligibleorgid, org.polid, org.orgpolicyid,
pp.planid, pp.rateid,
ps.ascinvoicedate,
case when ps.ascclaimfromdate > @startdate then ps.ascclaimfromdate
else @startdate end as premiumrundayFrom,
case when ps.ascclaimtodate < @enddate then ps.ascclaimtodate
else @enddate end as premiumrundayTo,
fts.effdate, fts.termdate,
case when fts.effdate > @startdate then fts.EffDate
else @startdate end as ascStartDate,
case when fts.termdate < @enddate then fts.termdate
else @enddate end as ascEndDate
FROM premiumschedule ps (nolock)
inner join orgpolicy org (nolock)
on org.ascinvoicerungroup between ps.premiumrundayfrom and ps.premiumrundayto
inner join FundingTypeStatus fts
on fts.orgpolicyid = org.orgpolicyid
and fts.fundtype = 'ASC'
and ((fts.effdate between @startdate and @enddate)
or (fts.termdate between @startdate and @enddate)
or (fts.effdate < @startdate and fts.termdate > @enddate))
inner join eligibilityorg o (nolock)
on org.eligibleorgid = o.eligibleorgid
inner join policydef pd (nolock)
on pd.polid = org.polid
inner join policyplans pp (nolock)
on pp.polid = org.polid
inner join program p (nolock)
on pd.programid = p.programid
left join orgaffiliation af with (nolock)
on org.eligibleorgid = af.childid
WHERE ps.premiumscheduleid = @ScheduleID
AND org.orgpolicyid <> ''


SELECT DISTINCT z.rateid, e.enrollid, z.ascstartdate, z.ascenddate
into tbltmptbltest FROM enrollment E
inner join tbltmpgroup z
on e.rateid = z.rateid


CREATE UNIQUE CLUSTERED INDEX IDXTempTable ON tbltmptbltest(enrollid)
create index IDXTemptableDates on tbltmptbltest(ascstartdate,ascenddate)


select distinct t.*
from tbltmpgroup t
where rateid in (
select distinct t.rateid from VW_ASC_Billing)
order by billorgid
truncate table tbltmpgroup

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-09-24 : 17:12:44
http://www.sqlteam.com/article/stored-procedures-returning-data
Go to Top of Page
   

- Advertisement -