Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL query

Posted on 2016-07-25
9
Medium Priority
?
69 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 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 143

Expert Comment

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

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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 41

Assisted Solution

by:Sharath
Sharath earned 500 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 30

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

719 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