Hi,I have a query below that I think is close to what I need, but I need to add a column(s) that has the Number of APPROVED claims Number of ENTERED claimsNumber of PENDING claimsAs of now, I am not sure how to get the totals, grouped by the batch.[code="sql"]DECLARE @CLAIMS intDECLARE @from_date_entered dateDECLARE @to_date_entered date----------------------------SET @from_date_entered = GETDATE() SET @to_date_entered = GETDATE() --SET @from_date_entered = N'03/08/2016'--SET @to_date_entered = N'03/14/2016'----------------------------SELECT @CLAIMS = batchtype_idFROM batchtypeWHERE batchtype_ud = 'CLAIMS'DECLARE @begin smalldatetimeSELECT @begin = CONVERT(smalldatetime, @from_date_entered)DECLARE @end smalldatetimeSELECT @end = DATEADD (dd,1,CONVERT(smalldatetime, @to_date_entered))DECLARE @begind smalldatetimeSELECT @begind = CONVERT(smalldatetime, @from_date_entered)DECLARE @endd smalldatetimeSELECT @endd = CONVERT(smalldatetime, @to_date_entered)DECLARE @CompanyName varchar(100)SELECT @CompanyName = environment_info.company_nameFROM environment_infoIF OBJECT_ID('tempdb..#rpt_data') IS NOT NULLbegin drop table #rpt_dataendCREATE TABLE #rpt_data (CompanyName varchar(100) NULL, Batch char(3) NULL, UserName varchar(35) NULL, SQLUserName varchar (25) NULL, claim_form_type_id int null, --altered 11/25/02 Claim_type varchar (10) NULL, status_type varchar(15) NULL, each int NULL, member_last varchar(35) NULL, fromdate smalldatetime NULL, todate smalldatetime NULL)INSERT INTO #rpt_data ( CompanyName, Batch, UserName, /*This field is named batch_sql_user_name in BALI */ SQLUserName, claim_form_type_id,--altered 11/25/02 Claim_type, status_type, each, member_last, fromdate, todate )/*************************************************** GetBatch where length is 3select * from claim_status***/SELECT DISTINCT @CompanyName, substring(batch_user.batch, 1, 3) as batch_init, batch_user.batch as user_name, batch_user.batch_sql_user_name, claim_form_type_id,--altered 11/25/02 null,--altered 11/25/02 claim_status.claim_status_ud, claim.claim_id, claim.member_last_name as member_last, @begind, @enddFROM batch_user inner join batchtype on batch_user.batchtype_id = batchtype.batchtype_id, claim inner join claim_status on claim.claim_status_id = claim_status.claim_status_id WHERE len(batch_user.batch) = 3 and substring(claim.claim_ud, 9, 3) = batch_user.batch and (claim.date_created < @end AND claim.date_created >= @begin) --and batchtype.batchtype_id = @CLAIMS--altered 11/25/02GROUP BY claim.claim_form_type_id, batch_user.batch_sql_user_name, batch_user.batch, claim_status.claim_status_ud, claim.member_last_name, claim.claim_id/*************************************************** GetBatch where length is 2***/INSERT INTO #rpt_data ( CompanyName, Batch, UserName, /*This field is named batch_sql_user_name in BALI */ SQLUserName, claim_form_type_id, Claim_type, status_type, each, member_last, fromdate, todate )SELECT DISTINCT @CompanyName, substring(batch_user.batch, 1, 2) as batch_init, batch_user.batch as user_name, batch_user.batch_sql_user_name, claim_form_type_id, null,--altered claim_status.claim_status_ud,--altered claim.claim_id, claim.member_last_name as member_last, @begind, @enddFROM batch_user inner join batchtype on batch_user.batchtype_id = batchtype.batchtype_id, claim inner join claim_status on claim.claim_status_id = claim_status.claim_status_id WHERE len(batch_user.batch) = 2 and substring(claim.claim_ud, 9, 2) = batch_user.batch and (claim.date_created < @end AND claim.date_created >= @begin) --and batchtype.batchtype_id = @CLAIMS--altered 11/25/02GROUP BY claim.claim_form_type_id, batch_user.batch_sql_user_name, batch_user.batch, claim_status.claim_status_ud, claim.member_last_name,claim.claim_id/*************************************************** GetBatch where length is 1***/INSERT INTO #rpt_data ( CompanyName, Batch, UserName, /*This field is named batch_sql_user_name in BALI */ SQLUserName, claim_form_type_id, Claim_type, status_type, each, member_last, fromdate, todate )SELECT DISTINCT @CompanyName, substring(batch_user.batch, 1, 1) as batch_init, batch_user.batch as user_name, batch_user.batch_sql_user_name, null,--altered claim_status.claim_status_ud,--altered claim_status.claim_status_ud, claim.claim_id, claim.member_last_name as member_last, @begind, @enddFROM batch_user inner join batchtype on batch_user.batchtype_id = batchtype.batchtype_id, claim inner join claim_status on claim.claim_status_id = claim_status.claim_status_id WHERE len(batch_user.batch) = 1 and substring(claim.claim_ud, 9, 1) = batch_user.batch and (claim.date_created < @end AND claim.date_created >= @begin) --and batchtype.batchtype_id = @CLAIMS--altered 11/25/02GROUP BY claim.claim_form_type_id, batch_user.batch_sql_user_name, batch_user.batch, claim_status.claim_status_ud, claim.member_last_name,claim.claim_idupdate #rpt_dataset claim_type = 'HCFA'where (claim_form_type_id = 2 or claim_form_type_id is null)update #rpt_dataset claim_type = 'UB92'where (claim_form_type_id = 1)SELECT * FROM #rpt_data [/code]
↧