Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:10:40+00:00 2026-06-06T19:10:40+00:00

I have large table, with around 200 fields. Around a 100 of those fields

  • 0

I have large table, with around 200 fields. Around a 100 of those fields are to be mapped to one field when creating a dimension table from it. The problem is I have to add the values of those 100 fields one-by-one through like a 100 insert statements. Is there like a loop or something with which i can achieve this more efficiently?

Here’s an example of the code:

    insert into DimTableA(visit_no, patient, facility, icd9, icd9_flag, ip_op)
    select D.registration, D3.med_number, D3.Hosp_Id, D.final_diagnosis_18,'d',IF(D3.Admit_Type in(1,2,3),'Inpatient','Outpatient'),
    from svch_dischs3_s D3, svch_diags_s D

    insert into DimTableA(visit_no, patient, facility, icd9, icd9_flag, ip_op)
    select D.registration, D3.med_number, D3.Hosp_Id, D.final_diagnosis_19,'d',IF(D3.Admit_Type in(1,2,3),'Inpatient','Outpatient'),
    from svch_dischs3_s D3, svch_diags_s D

    insert into DimTableA(visit_no, patient, facility, icd9, icd9_flag, ip_op)
    select D.registration, D3.med_number, D3.Hosp_Id, D.final_diagnosis_20,'d',IF(D3.Admit_Type in(1,2,3),'Inpatient','Outpatient'),
    from svch_dischs3_s D3, svch_diags_s D;

……… and so on

The only field name that changes is the ‘icd9’ input( i.e D.final_diagnosis_18, final_diagnosis_19, final_diagnosis_20 ….)

Any help would be really appreciated, lads. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:10:41+00:00Added an answer on June 6, 2026 at 7:10 pm

    You could unpivot those columns using a cross join to a fixed set of numbers like this:

    insert into DimTableA (
      visit_no,
      patient,
      facility,
      icd9,
      icd9_flag,
      ip_op
    )
    select
      D.registration,
      D3.med_number,
      D3.Hosp_Id,
      case N.number
        when 1 then D.final_diagnosis_18
        when 2 then D.final_diagnosis_19
        when 3 then D.final_diagnosis_20
        ...
      end,
      'd',
      IF(D3.Admit_Type in(1,2,3),'Inpatient','Outpatient')
    from
      svch_dischs3_s D3,
      svch_diags_s D,
      (
        select 1 as number union all
        select 2           union all
        select 3           union all
        ...  /* up to the number of columns to unpivot */
      ) N
    

    You could create and populate a persistent numbers table instead of the inline view and use the necessary subset of that table in your query. In that case the query would change like this

    ...
    from
      svch_dischs3_s D3,
      svch_diags_s D,
      numbers N
    where N.number between 1 and … /* the number of columns to unpivot */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large table with around 100 columns and hence is difficult to
I have a large table with around half a million rows which is taking
I have a large table I imported from an Excel spreadsheet. For five of
I have a data table with 600,000 records that is around 25 megabytes large.
I have an extremely large db table (around 30GB data file), and I started
I have a really large table (around 32 columns and 1000+ rows) which I'm
I am creating a large table dynamically using Javascript. I have realised the time
I'm currently have around 100 rows in a table on my website, which include
I am working in one real-estate website and I have large database around 250
I have a substantial database... not a very large one - around 1gb of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.