Solved

SQL query

Posted on 2016-07-25
9
46 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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

706 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

19 Experts available now in Live!

Get 1:1 Help Now