|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Help with Stored Proc + cursor |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|