| Author |
Topic |
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2008-01-02 : 06:23:23
|
| CREATE PROCEDURE VEHICLE_OUTSTANDING @SDt Varchar(10),@EDt Varchar(10),@Cocode Varchar(5),@Brcode Varchar(5),@Loccode Varchar(5),@GLCode Varchar(6) ASSelect (Loccode+Glcode+Slcode) as LGS,Refno,Refdt Into #VST from Trans_Transnarr Where Trtype='VES' and (Refdt>=Convert(Datetime,@SDt,103) and Refdt<=Convert(Datetime,@EDt,103)) and (Cancflg Is Null or Cancflg='R') and Loccode=@Loccode and Glcode=@GlcodeSelect Sl.Sldesc,Tr.Loccode,Tr.Glcode,Tr.Slcode,X.Refno,Convert(Varchar,X.Refdt,103) as Refdt,Sum(Case When Tr.Trtype='VES' Then Tr.Tramt Else 0 End) as VES,Sum(Case When Tr.Trtype='DBN' Then Tr.Tramt Else 0 End) as DBN,Sum(Case When (Tr.Trtype='CPM' or Tr.Trtype='BPM') Then Tr.Tramt Else 0 End) as Refund, Sum(Case When (Tr.Trtype='JNL' and Tr.Drcrflag='D') Then Tr.Tramt Else 0 End) as JNLD,Sum(Case When Tr.Trtype='SPS' Then Tr.Tramt Else 0 End) as SPS,Sum(Case When (Tr.Trtype='CRT' or Tr.Trtype='BRT') Then Tr.Tramt Else 0 End) as Receipt,Sum(Case When Tr.Trtype='ADV' Then Tr.Tramt Else 0 End) as ADV,Sum(Case When Tr.Trtype='CRN' Then Tr.Tramt Else 0 End) as CRN,Sum(Case When (Tr.Trtype='JNL' and Tr.Drcrflag='C') Then Tr.Tramt Else 0 End) as JNLC,Sum(Case When Tr.Trtype='SRT' Then Tr.Tramt Else 0 End) as SRT Into #VOS from Trans_Journal Tr,Slmast Sl,#VST X Where (Sl.Loccode=@Loccode and Tr.Glcode=Sl.Glcode and Tr.Slcode=Sl.Slcode) and (Tr.Loccode+Tr.Glcode+Tr.Slcode)=X.LGS and (Tr.Cancflg Is Null or Tr.Cancflg='R') Group By Tr.Loccode,Tr.Glcode,Tr.Slcode,Sl.Sldesc,X.Refno,X.RefdtALTER TABLE #VOS ADD OPDR Float,OPCR FloatUPDATE #VOS SET #VOS.OPDR = S.DRAMT,#VOS.OPCR = S.CRAMT FROM #VOS, (SELECT GLCODE,SLCODE, (CASE WHEN DRCRFLAG = 'D' THEN OPBAL ELSE 0 END) AS DRAMT, (CASE WHEN DRCRFLAG = 'C' THEN OPBAL ELSE 0 END) AS CRAMT FROM OBDATA WHERE LOCCODE=@Loccode and GLCODE =@Glcode) S WHERE #VOS.GLCODE = S.GLCODE AND #VOS.SLCODE = S.SLCODENot able to Update OPDR & OPCRError Message is Invalid column name 'OPDR'.RegardsNirene Veshnav |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-02 : 06:48:35
|
Change your SELECT query to following:Select Sl.Sldesc,Tr.Loccode,Tr.Glcode,Tr.Slcode,X.Refno,Convert(Varchar,X.Refdt,103) as Refdt,Sum(Case When Tr.Trtype='VES' Then Tr.Tramt Else 0 End) as VES,Sum(Case When Tr.Trtype='DBN' Then Tr.Tramt Else 0 End) as DBN,Sum(Case When (Tr.Trtype='CPM' or Tr.Trtype='BPM') Then Tr.Tramt Else 0 End) as Refund, Sum(Case When (Tr.Trtype='JNL' and Tr.Drcrflag='D') Then Tr.Tramt Else 0 End) as JNLD,Sum(Case When Tr.Trtype='SPS' Then Tr.Tramt Else 0 End) as SPS,Sum(Case When (Tr.Trtype='CRT' or Tr.Trtype='BRT') Then Tr.Tramt Else 0 End) as Receipt,Sum(Case When Tr.Trtype='ADV' Then Tr.Tramt Else 0 End) as ADV,Sum(Case When Tr.Trtype='CRN' Then Tr.Tramt Else 0 End) as CRN,Sum(Case When (Tr.Trtype='JNL' and Tr.Drcrflag='C') Then Tr.Tramt Else 0 End) as JNLC,Sum(Case When Tr.Trtype='SRT' Then Tr.Tramt Else 0 End) as SRT, cast(0 as float) as OPDR, cast(0 as float) as OPDRInto #VOS from Trans_Journal Tr,Slmast Sl,#VST X Where (Sl.Loccode=@Loccode and Tr.Glcode=Sl.Glcode and Tr.Slcode=Sl.Slcode) and (Tr.Loccode+Tr.Glcode+Tr.Slcode)=X.LGS and (Tr.Cancflg Is Null or Tr.Cancflg='R') Group By Tr.Loccode,Tr.Glcode,Tr.Slcode,Sl.Sldesc,X.Refno,X.Refdt and Remove the ALTER TABLE statement.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|