MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 12th, 2004, 10:24 AM
Balaji Allam Balaji Allam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: USA
Posts: 15 Balaji Allam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Balaji Allam
Help with Stored Proc + cursor

Help..Help
I have a very li'l experience with Stored procs and I wrote a moderately SSP....Okay here is the deal:

Tables Accessed:
1.Contract (Fields in it are: Contract ID, ContractPrefix,CustomerID)
2.Rate Schedule(Fields: Rateschedulecode)
3.Daily Detail(Fields: ContractPrefix, Contract ID, AccountingDate, FlowDate,AllocatedNetQty,DailyDetailStatus,NominatedFlowDirection)

The Stored Proc I wrote is some'in like this:


DECLARE
@errno int,
@errmsg varchar(255),
@ForeverDate smalldatetime

SET @ForeverDate = '6/6/2079'

Select
cntr.RateScheduleCode,cntr.ContractPrefix,cntr.ContractID,cntr.EffectiveDate, cntr.DeactivateDate, DlyDtl.FlowDate from Contract cntr

INNER Join RateSchedule RtSch
on cntr.BusinessunitID= RtSch.BusinessunitID
and cntr.rateschedulecode=RtSch.rateschedulecode
and @ActiveDate BETWEEN RtSch.BeginDate and COALESCE(DATEADD(day, -1, RtSch.EndDate), @ForeverDate)

INNER Join Dailydetail DlyDtl
on cntr.BusinessunitID= DlyDtl.BusinessunitID
and cntr.CustomerID=DlyDtl.CustomerID
and cntr.ContractPrefix =DlyDtl.ContractPrefix
and cntr.ContractID=DlyDtl.ContractID

where cntr.BusinessUnitId=@BusinessUnitId
and cntr.CustomerID=@CustomerID
and @ActiveDate BETWEEN cntr.EffectiveDate and COALESCE(DATEADD(day, -1, cntr.DeactivateDate), @ForeverDate)
and RtSch.ContractPrefix in ('SA','TA','BA','PA')
and (Month(DlyDtl.accountingdate) =Month(@ActiveDate) and Year(DlyDtl.accountingdate) =Year(@ActiveDate))
and (DATEPART(m,DlyDtl.flowdate)<DATEPART(m,@ActiveDate) and DATEPART(y,DlyDtl.flowdate)<DATEPART(y,@ActiveDate))

order by DlyDtl.flowdate

IF @@ERROR <> 0
BEGIN
SET @errno = 58400
SET @errmsg = 'Select/Retrieval Problem in Stored Procedure: rpt_CSI005_GetContractandAdjustmentsbyContract_ssp'
raiserror @errno @errmsg
RETURN @errno
END
ELSE
RETURN 0
END
GO


My requirement is:

1> Add the AllocatedNetQty from a DailyDetail record with DlyDtl.DailyDetailStatus="Reverse" to the AllocatedNetQty of a DailyDetail record with DlyDtl.DailyDetailStatus="Restate" and the result will be stored as Total Adjustments and for the first time this will be initialized to 0
2>If DlyDtl.NominatedFlowDirection="Receipt" then subtract the above calculated qty from the Total Adjustments
3>Else if DlyDtl.NominatedFlowDirection="Delivery" then Add the above calculated qty to the Total Adjustments

Now this far I know that I need to write a cursor to the above stored proc to fulfil the requirement but that is what i am craving for....a li'l help from ya guys
Thx a bunch
BJ

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Help with Stored Proc + cursor


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT