|
Nav522
Starting Member
27 Posts |
Posted - 2010-03-23 : 12:33:43
|
| Am really in a confused state. I dont want to use a parameter now but i just want to add the Field called ClientID..It throws me an error saying Ambigous column.alter PROCEDURE [dbo].[sp_rptClaimsSummary43_BO]--@StartDate DateTime,--@EndDate DateTime@Frequency varchar(20)AS/* Dates Start*/declare @v_startdate datetime,@v_enddate datetimeBEGIN IF @Frequency = 'DECADE' begin select @v_startdate= cast('20000101' as datetime) ,@v_enddate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) end ELSE IF @Frequency = 'YEARLY' begin select @v_startdate= dateadd(year, datediff(year, 0, getdate()), 0) ,@v_enddate= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) end ELSE if @Frequency = 'MONTHLY' begin select @v_startdate =dateadd(Month, datediff(Month, 0, getdate())-1, 0) ,@v_enddate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) endENDSelect 'BCCLARGEBC'=IsNull(Sum(Cast(ClaimClientFieldValue as Money)),0) into #BCCLARGEBC from tblClaims c Inner Join tblClaimProducts cp on cp.claimID=c.claimID Inner Join tblActions a on cp.claimID=a.claimID and cp.productID=a.productID Inner Join tblClaimClientFields ccf on ccf.claimID=c.claimID and ccf.clientID=c.clientID Where a.actionCode =153 and cp.claimProductInvoiceDate between @v_startdate and @v_enddate and a.actionOverriddenFlag = 0 and a.actionDeletedFlag = 0 and ccf.clientID=104 and ccf.clientFieldID=117 and left(claimclientbusunit,3) in ('70f','661','662','663','666','667','668','669','670','672','70c','999','41c') and (Select top 1 claimID from tblActions where actionDeletedFlag=0 and actionOverriddenFlag=0 and claimID=cp.claimID and productID=cp.productID and actionCode in (186, 190, 198, 222, 224, 225, 233, 236, 244, 248, 250, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 271, 281, 307, 306, 308, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 339, 340, 342, 343, 344, 345, 347, 350, 312, 313, 314, 315, 316, 317, 318, 319, 320)) is null Group by a.ActionCodeSelect 'BCCISGBC'=IsNull(Sum(Cast(ClaimClientFieldValue as Money)),0) into #BCCISGBC from tblClaims c Inner Join tblClaimProducts cp on cp.claimID=c.claimID Inner Join tblActions a on cp.claimID=a.claimID and cp.productID=a.productID Inner Join tblClaimClientFields ccf on ccf.claimID=c.claimID and ccf.clientID=c.clientID Where a.actionCode =153 and cp.claimProductInvoiceDate between @v_startdate and @v_enddate and a.actionOverriddenFlag = 0 and a.actionDeletedFlag = 0 and ccf.clientID=104 and ccf.clientFieldID=117 and left(claimclientbusunit,3) in ('60u','60m','673','63m','64m','64r','651') and (Select top 1 claimID from tblActions where actionDeletedFlag=0 and actionOverriddenFlag=0 and claimID=cp.claimID and productID=cp.productID and actionCode in (186, 190, 198, 222, 224, 225, 233, 236, 244, 248, 250, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 271, 281, 307, 306, 308, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 339, 340, 342, 343, 344, 345, 347, 350, 312, 313, 314, 315, 316, 317, 318, 319, 320)) is null Group by a.ActionCodeSelect 'UniCareBC'=IsNull(Sum(Cast(ClaimClientFieldValue as Money)),0) into #UniCareBC from tblClaims c Inner Join tblClaimProducts cp on cp.claimID=c.claimID Inner Join tblActions a on cp.claimID=a.claimID and cp.productID=a.productID Inner Join tblClaimClientFields ccf on ccf.claimID=c.claimID and ccf.clientID=c.clientID Where a.actionCode =153 and cp.claimProductInvoiceDate between @v_startdate and @v_enddate and a.actionOverriddenFlag = 0 and a.actionDeletedFlag = 0 and ccf.clientfieldID=117 and (Select top 1 claimID from tblActions where actionDeletedFlag=0 and actionOverriddenFlag=0 and claimID=cp.claimID and productID=cp.productID and actionCode in (186, 190, 198, 222, 224, 225, 233, 236, 244, 248, 250, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 271, 281, 307, 306, 308, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 339, 340, 342, 343, 344, 345, 347, 350, 312, 313, 314, 315, 316, 317, 318, 319, 320)) is nullSelect 'Client'='BCCLARGE',a.actionCode, 'Claims'=isNull(Count(c.claimID),0), 'ClaimSum'=sum( Case c.providerID When 2435 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2729 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2574 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2736 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2593 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2556 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2635 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2322 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2321 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2542 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2548 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2647 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2071 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2082 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2533 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) Else c.ClaimTotalBill End),clientID-- This is the one i have added into #xxx from tblClaims c Inner Join tblClaimProducts cp on cp.claimID=c.claimID Inner Join tblActions a on cp.claimID=a.claimID and cp.productID=a.productID Inner Join tblClaimClientFields ccf on ccf.claimID=c.claimID and ccf.clientID=c.clientID Where a.actionCode in (309, 324) and a.ActionDate between @v_startdate and @v_enddate and ccf.clientID=104 and ccf.clientFieldID=10 and a.actionOverriddenFlag = 0 and a.actionDeletedFlag = 0 and left(claimclientbusunit,3) in ('70f','661','662','663','666','667','668','669','670','672','70c','999','41c') and (Select top 1 claimID from tblActions where actionDeletedFlag=0 and actionOverriddenFlag=0 and claimID=cp.claimID and productID=cp.productID and actionCode in (186, 190, 198, 222, 224, 225, 233, 236, 244, 248, 250, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 271, 281, 307, 306, 308, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 339, 340, 342, 343, 344, 345, 347, 350, 312, 313, 314, 315, 316, 317, 318, 319, 320)) is null Group by a.actionCode,clientIDInsert Into #xxxSelect 'Client'='BCCISG',a.actionCode, 'Claims'=isNull(Count(c.claimID),0), 'ClaimSum'=sum( Case c.providerID When 2435 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2729 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2574 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2736 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2593 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2556 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2635 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2322 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2321 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2542 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2548 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2647 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2071 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2082 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2533 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) Else c.ClaimTotalBill End),clientID -- Again i have used it here from tblClaims c Inner Join tblClaimProducts cp on cp.claimID=c.claimID Inner Join tblActions a on cp.claimID=a.claimID and cp.productID=a.productID Inner Join tblClaimClientFields ccf on ccf.claimID=c.claimID and ccf.clientID=c.clientID Where a.actionCode in (309, 324) and a.ActionDate between @v_startdate and @v_enddate and ccf.clientID=104 and ccf.clientFieldID=10 and a.actionOverriddenFlag = 0 and a.actionDeletedFlag = 0 and left(claimclientbusunit,3) in ('60u','60m','673','63m','64m','64r','651') and (Select top 1 claimID from tblActions where actionDeletedFlag=0 and actionOverriddenFlag=0 and claimID=cp.claimID and productID=cp.productID and actionCode in (186, 190, 198, 222, 224, 225, 233, 236, 244, 248, 250, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 271, 281, 307, 306, 308, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 339, 340, 342, 343, 344, 345, 347, 350, 312, 313, 314, 315, 316, 317, 318, 319, 320)) is null Group by a.actionCode,clientIDInsert Into #xxxSelect 'Client'='UniCare',a.actionCode, 'Claims'=isNull(Count(c.claimID),0), 'ClaimSum'=sum( Case c.providerID When 2435 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2729 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2574 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2736 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2593 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2556 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2635 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2322 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2321 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2542 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2548 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2647 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2071 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2082 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2533 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) Else c.ClaimTotalBill End),clientID --Agian from tblClaims c Inner Join tblClaimProducts cp on cp.claimID=c.claimID Inner Join tblActions a on cp.claimID=a.claimID and cp.productID=a.productID Inner Join tblClaimClientFields ccf on ccf.claimID=c.claimID and ccf.clientID=c.clientID Where a.actionCode = 309 and a.ActionDate between @v_startdate and @v_enddate and ccf.clientID=118 and a.actionOverriddenFlag = 0 and a.actionDeletedFlag = 0 and (Select top 1 claimID from tblActions where actionDeletedFlag=0 and actionOverriddenFlag=0 and claimID=cp.claimID and productID=cp.productID and actionCode in (186, 190, 198, 222, 224, 225, 233, 236, 244, 248, 250, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 271, 281, 307, 306, 308, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 339, 340, 342, 343, 344, 345, 347, 350, 312, 313, 314, 315, 316, 317, 318, 319, 320)) is null Group by a.actionCode,clientIDInsert Into #xxxSelect 'Client'='UniCare',a.actionCode, 'Claims'=isNull(Count(c.claimID),0), 'ClaimSum'=sum( Case c.providerID When 2435 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2729 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2574 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2736 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2593 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2556 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2635 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2322 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2321 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2542 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2548 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2647 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2071 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2082 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) When 2533 then c.ClaimTotalBill + isNull(c.claimProviderLateCharges,0) Else c.ClaimTotalBill End),clientID from tblClaims c Inner Join tblClaimProducts cp on cp.claimID=c.claimID Inner Join tblActions a on cp.claimID=a.claimID and cp.productID=a.productID Where a.actionCode = 324 and a.ActionDate between @v_startdate and @v_enddate and a.actionOverriddenFlag = 0 and a.actionDeletedFlag = 0 and c.clientID=118 and (Select top 1 claimID from tblActions where actionDeletedFlag=0 and actionOverriddenFlag=0 and claimID=cp.claimID and productID=cp.productID and actionCode in (186, 190, 198, 222, 224, 225, 233, 236, 244, 248, 250, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 271, 281, 307, 306, 308, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 339, 340, 342, 343, 344, 345, 347, 350, 312, 313, 314, 315, 316, 317, 318, 319, 320)) is null Group by a.actionCode,clientID |
 |
|