Solved

SQL query

Posted on 2016-07-25
9
52 Views
Last Modified: 2016-08-22
declare @bcbs_load_date char(8)
INSERT INTO tbl_claims_bcbs_pharmacy_test
(MASTER_CONSUMER_ID,
CLAIM_NUMBER,
CLAIM_ADJUSTMENT_NUMBER,
CLAIM_DISPOSITION_CODE,
FILLED_DATE,
NDC_NUMBER,
DEA_NUMBER,
PHARMACY_NUMBER,
PHARMACY_NAME,
THERAPEUTIC_CLASS,
QUANTITY_DISPENSED,
DAYS_SUPPLIED,
FORMULARY_INDICATOR,
RETAIL_MAIL_INDICATOR,
BILLED_CHARGES,
[YEAR],
QUARTER,
[MONTH],
PATIENT_RESPONSIBILITY_AMOUNT,
PAID_AMOUNT,
SCRIPT_WRITTEN_DATE,
ALLOWED_AMT,
RX_NUMBER,
INGREDIENT_COST,
COPAY,
DRUG_NAME,
DISPENSED_BRAND_GENERIC_CODE,
GENERIC_PRODUCT_IDENTIFIER,
OTHER_PARTY_LIABILITY_AMOUNT,
PAID_DATE,
CLAIM_SOURCE_SYSTEM,
COINSRN_AMT,
DDCTBL_AMT,
MBR_SNCTNS_PNLTYS_AMT,
PAT_PAID_DFRNTL_AMT,
DISPENSE_AS_WRITTEN,
DISPENSE_DAYS_COUNT,
DRUG_STRENGTH,
MANUFACTURER_NAME,
INCURRED_YEAR_MONTH,
CLAIM_MAX_REVISION_DATE,
LAST_CLAIM_ADJUSTMENT,
PRIMARY_CARRIER_RESPONSIBLE_FOR_CLAIM,
ADJUDICATION_DATE,
CLAIM_PROCESSING_DATE,
CLAIM_ACTION_TYPE,
NPI,
PATIENT_ACCOUNT_NUMBER,
STATUS_CODE,
month_ending
)
SELECT  MASTER_CONSUMER_ID ,
        CLAIM_NUMBER ,
        CLAIM_ADJUSTMENT_NUMBER ,
        CLAIM_DISPOSITION_CODE ,
        FILLED_DATE ,
        NDC_NUMBER ,
        DEA_NUMBER ,
        PHARMACY_NUMBER ,
        PHARMACY_NAME ,
        THERAPEUTIC_CLASS ,
        SUM(cast(isnull(QUANTITY_DISPENSED ,'0.00') as float)) as [QUANTITY_DISPENSED],
        SUM(cast(isnull(DAYS_SUPPLIED ,'0') as float)) as [DAYS_SUPPLIED],
        FORMULARY_INDICATOR ,
        RETAIL_MAIL_INDICATOR ,
        SUM(cast(isnull(BILLED_CHARGES, '0.00') as money)) as [BILLED_CHARGES] ,
        [YEAR] ,
        QUARTER ,
        [MONTH] ,
        SUM(cast(isnull(PATIENT_RESPONSIBILITY_AMOUNT, '0.00') as money)) as [PATIENT_RESPONSIBILITY_AMOUNT] ,
        SUM(cast(isnull(PAID_AMOUNT, '0.00') as money)) as [PAID_AMOUNT] ,
        SCRIPT_WRITTEN_DATE ,
        SUM(cast(isnull(ALLOWED_AMT, '0.00') as money)) as [ALLOWED_AMT] ,
        RX_NUMBER ,
        sum(cast(isnull(INGREDIENT_COST,'0.00') as money)) as [INGREDIENT_COST],
        sum(cast(isnull(COPAY,'0.00') as money)) as [COPAY],
        DRUG_NAME ,
        DISPENSED_BRAND_GENERIC_CODE ,
        GENERIC_PRODUCT_IDENTIFIER ,
        sum(cast(isnull(OTHER_PARTY_LIABILITY_AMOUNT ,'0.00')as money)) as [OTHER_PARTY_LIABILITY_AMOUNT],
        PAID_DATE ,
        CLAIM_SOURCE_SYSTEM ,
        sum(cast(isnull(COINSRN_AMT ,'0.00')as money)) as [COINSRN_AMT],
        sum(cast(isnull(DDCTBL_AMT ,'0.00')as money)) as [DDCTBL_AMT],
        sum(cast(isnull(MBR_SNCTNS_PNLTYS_AMT ,'0.00')as money)) as [MBR_SNCTNS_PNLTYS_AMT],
        sum(cast(isnull(PAT_PAID_DFRNTL_AMT ,'0.00')as money)) as [PAT_PAID_DFRNTL_AMT],
        DISPENSE_AS_WRITTEN ,
        DISPENSE_DAYS_COUNT ,
        DRUG_STRENGTH ,
        MANUFACTURER_NAME ,
        INCURRED_YEAR_MONTH ,
        CLAIM_MAX_REVISION_DATE ,
        LAST_CLAIM_ADJUSTMENT ,
        PRIMARY_CARRIER_RESPONSIBLE_FOR_CLAIM ,
        ADJUDICATION_DATE ,
        CLAIM_PROCESSING_DATE
        CLAIM_ACTION_TYPE ,
        NPI ,
        PATIENT_ACCOUNT_NUMBER ,
        STATUS_CODE,
        @bcbs_load_date
FROM    tbl_claims_bcbs_pharmacy_stage_test AS a
WHERE   NOT EXISTS ( SELECT MASTER_CONSUMER_ID ,
                            CLAIM_NUMBER ,
                            CLAIM_ADJUSTMENT_NUMBER ,
                            CLAIM_DISPOSITION_CODE
                     FROM   tbl_claims_bcbs_pharmacy AS b
                     WHERE  a.MASTER_CONSUMER_ID = b.MASTER_CONSUMER_ID
                            AND a.CLAIM_NUMBER = b.CLAIM_NUMBER
                            AND a.CLAIM_ADJUSTMENT_NUMBER = b.CLAIM_ADJUSTMENT_NUMBER
                            AND a.CLAIM_DISPOSITION_CODE = b.CLAIM_DISPOSITION_CODE )

Group by  MASTER_CONSUMER_ID, claim_number, claim_adjustment_number, claim_disposition_code, filled_date, ndc_number, claim_processing_date, pharmacy_number , pharmacy_name ,therapeutic_class,
QUANTITY_DISPENSED,DAYS_SUPPLIED,dea_number, formulary_indicator ,retail_mail_indicator,[YEAR] ,quarter ,[MONTH], script_written_date , rx_number ,drug_name , dispensed_brand_generic_code ,generic_product_identifier,paid_date ,
claim_source_system, dispense_as_written , dispense_days_count , drug_strength , manufacturer_name , incurred_year_month, claim_max_revision_date , last_claim_adjustment ,
primary_carrier_responsible_for_claim , adjudication_date, claim_action_type , npi , patient_account_number , status_code  

 

 Error:

The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.
0
Comment
Question by:Member_2_7969213
9 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points (awarded by participants)
ID: 41728138
the error is "clear".
your select has more or less fields

or it migth be in a trigger on the inserted table...

please just count ( i would really love the databases to provide the counts, but well)
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41728144
and i counted 48 vs 50
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41728150
to troubleshoot, but both lists i t an excel file, side by side, to see which columns are mismatching
0
 

Author Comment

by:Member_2_7969213
ID: 41728225
Thank u Hengel

I counted and checked in excel too all there are 50 columns in both insert and select
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points (awarded by participants)
ID: 41728261
i think i found it
 CLAIM_PROCESSING_DATE
        CLAIM_ACTION_TYPE

a comma is missing there...
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 125 total points (awarded by participants)
ID: 41728266
You missed a comma after CLAIM_PROCESSING_DATE in the SELECT clause. Added that.
declare @bcbs_load_date char(8)
INSERT INTO tbl_claims_bcbs_pharmacy_test
(
MASTER_CONSUMER_ID,
CLAIM_NUMBER,
CLAIM_ADJUSTMENT_NUMBER, 
CLAIM_DISPOSITION_CODE, 
FILLED_DATE, 
NDC_NUMBER, 
DEA_NUMBER, 
PHARMACY_NUMBER,
PHARMACY_NAME, 
THERAPEUTIC_CLASS, 
QUANTITY_DISPENSED,
DAYS_SUPPLIED, 
FORMULARY_INDICATOR,
RETAIL_MAIL_INDICATOR,
BILLED_CHARGES, 
[YEAR],
QUARTER, 
[MONTH], 
PATIENT_RESPONSIBILITY_AMOUNT, 
PAID_AMOUNT, 
SCRIPT_WRITTEN_DATE, 
ALLOWED_AMT, 
RX_NUMBER, 
INGREDIENT_COST, 
COPAY, 
DRUG_NAME, 
DISPENSED_BRAND_GENERIC_CODE, 
GENERIC_PRODUCT_IDENTIFIER,
OTHER_PARTY_LIABILITY_AMOUNT,
PAID_DATE, 
CLAIM_SOURCE_SYSTEM, 
COINSRN_AMT, 
DDCTBL_AMT, 
MBR_SNCTNS_PNLTYS_AMT,
PAT_PAID_DFRNTL_AMT, 
DISPENSE_AS_WRITTEN, 
DISPENSE_DAYS_COUNT, 
DRUG_STRENGTH, 
MANUFACTURER_NAME,
INCURRED_YEAR_MONTH, 
CLAIM_MAX_REVISION_DATE,
LAST_CLAIM_ADJUSTMENT,
PRIMARY_CARRIER_RESPONSIBLE_FOR_CLAIM, 
ADJUDICATION_DATE, 
CLAIM_PROCESSING_DATE,
CLAIM_ACTION_TYPE, 
NPI, 
PATIENT_ACCOUNT_NUMBER, 
STATUS_CODE, 
month_ending
)
SELECT  MASTER_CONSUMER_ID ,
        CLAIM_NUMBER ,
        CLAIM_ADJUSTMENT_NUMBER ,
        CLAIM_DISPOSITION_CODE ,
        FILLED_DATE ,
        NDC_NUMBER ,
        DEA_NUMBER ,
        PHARMACY_NUMBER ,
        PHARMACY_NAME ,
        THERAPEUTIC_CLASS ,
        SUM(cast(isnull(QUANTITY_DISPENSED ,'0.00') as float)) as [QUANTITY_DISPENSED],
        SUM(cast(isnull(DAYS_SUPPLIED ,'0') as float)) as [DAYS_SUPPLIED],
        FORMULARY_INDICATOR ,
        RETAIL_MAIL_INDICATOR ,
        SUM(cast(isnull(BILLED_CHARGES, '0.00') as money)) as [BILLED_CHARGES] ,
        [YEAR] ,
        QUARTER ,
        [MONTH] ,
        SUM(cast(isnull(PATIENT_RESPONSIBILITY_AMOUNT, '0.00') as money)) as [PATIENT_RESPONSIBILITY_AMOUNT] ,
        SUM(cast(isnull(PAID_AMOUNT, '0.00') as money)) as [PAID_AMOUNT] ,
        SCRIPT_WRITTEN_DATE ,
        SUM(cast(isnull(ALLOWED_AMT, '0.00') as money)) as [ALLOWED_AMT] ,
        RX_NUMBER ,
        sum(cast(isnull(INGREDIENT_COST,'0.00') as money)) as [INGREDIENT_COST],
        sum(cast(isnull(COPAY,'0.00') as money)) as [COPAY],
        DRUG_NAME ,
        DISPENSED_BRAND_GENERIC_CODE ,
        GENERIC_PRODUCT_IDENTIFIER ,
        sum(cast(isnull(OTHER_PARTY_LIABILITY_AMOUNT ,'0.00')as money)) as [OTHER_PARTY_LIABILITY_AMOUNT],
        PAID_DATE ,
        CLAIM_SOURCE_SYSTEM ,
        sum(cast(isnull(COINSRN_AMT ,'0.00')as money)) as [COINSRN_AMT],
        sum(cast(isnull(DDCTBL_AMT ,'0.00')as money)) as [DDCTBL_AMT],
        sum(cast(isnull(MBR_SNCTNS_PNLTYS_AMT ,'0.00')as money)) as [MBR_SNCTNS_PNLTYS_AMT],
        sum(cast(isnull(PAT_PAID_DFRNTL_AMT ,'0.00')as money)) as [PAT_PAID_DFRNTL_AMT],
        DISPENSE_AS_WRITTEN ,
        DISPENSE_DAYS_COUNT ,
        DRUG_STRENGTH ,
        MANUFACTURER_NAME ,
        INCURRED_YEAR_MONTH ,
        CLAIM_MAX_REVISION_DATE ,
        LAST_CLAIM_ADJUSTMENT ,
        PRIMARY_CARRIER_RESPONSIBLE_FOR_CLAIM ,
        ADJUDICATION_DATE ,
        CLAIM_PROCESSING_DATE,
        CLAIM_ACTION_TYPE ,
        NPI ,
        PATIENT_ACCOUNT_NUMBER ,
        STATUS_CODE,
        @bcbs_load_date
FROM    tbl_claims_bcbs_pharmacy_stage_test AS a
WHERE   NOT EXISTS ( SELECT MASTER_CONSUMER_ID ,
                            CLAIM_NUMBER ,
                            CLAIM_ADJUSTMENT_NUMBER ,
                            CLAIM_DISPOSITION_CODE
                     FROM   tbl_claims_bcbs_pharmacy AS b
                     WHERE  a.MASTER_CONSUMER_ID = b.MASTER_CONSUMER_ID
                            AND a.CLAIM_NUMBER = b.CLAIM_NUMBER
                            AND a.CLAIM_ADJUSTMENT_NUMBER = b.CLAIM_ADJUSTMENT_NUMBER
                            AND a.CLAIM_DISPOSITION_CODE = b.CLAIM_DISPOSITION_CODE )

Group by  MASTER_CONSUMER_ID, claim_number, claim_adjustment_number, claim_disposition_code, filled_date, ndc_number, claim_processing_date, pharmacy_number , pharmacy_name ,therapeutic_class, 
QUANTITY_DISPENSED,DAYS_SUPPLIED,dea_number, formulary_indicator ,retail_mail_indicator,[YEAR] ,quarter ,[MONTH], script_written_date , rx_number ,drug_name , dispensed_brand_generic_code ,generic_product_identifier,paid_date ,
claim_source_system, dispense_as_written , dispense_days_count , drug_strength , manufacturer_name , incurred_year_month, claim_max_revision_date , last_claim_adjustment , 
primary_carrier_responsible_for_claim , adjudication_date, claim_action_type , npi , patient_account_number , status_code

Open in new window

0
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 125 total points (awarded by participants)
ID: 41729003
That's a consequence of optional keywords.

You can SELECT field1, field2 ..., you also SELECT field1 field2, but that is short for SELECT  field1 AS field2. If AS would not be optional, parsing that would point out an error of either a missing comma or missing AS.

So , if T-SQL would be more strict with such things, there'd be no chance for such an error, which only reveals if the number of fields is essential, manually inspecting just a SELECT having such an error you don't see a field missing in so many columns.

Since Guy talked of 48 vs 50, I'd expect another missing comma or any other missing field.

Bye, Olaf
0
 

Author Comment

by:Member_2_7969213
ID: 41731708
Friends thank You!! Yes Comma was missing
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL 2008 SSIS import 11 50
Need to update TableA to TableB 6 33
SQL - How to list all tables participating in a query 7 37
MS SQL Pivot table help 4 5
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now