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

  • Home
  • SEARCH
  • 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 8733867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:43:59+00:00 2026-06-13T09:43:59+00:00

I have a SQL table with many columns, and in particular a set of

  • 0

I have a SQL table with many columns, and in particular a set of columns containing codes. For each of the code columns there are also corresponding information columns pertaining to each of the code columns. I need to be able to turn one record into multiple returned records (i.e. one record for each code). This is an old table with legacy data along with software code, and it would be very difficult to normalize the table (even though it really needs to be).

Here is the table:

CO_ComapnyInformation
                (
                 ProjectID
                ,SubContractor_OrgID
                ,BudGet
                ,ContractDays
                ,ContractCode
                ,ContractCode1
                ,ContractCode2
                ,ContractCode3
                ,ContractCode4
                ,ContractCode5
                ,ContractCodeAmt
                ,ContractCode1Amt
                ,ContractCode2Amt
                ,ContractCode3Amt
                ,ContractCode4Amt
                ,ContractCode5Amt
                ,ContractStartDate
                ,ContractCodeBudget
                ,ContractCodeBudget1
                ,ContractCodeBudget2
                ,ContractCodeBudget3
                ,ContractCodeBudget4
                ,ContractCodeBudget5
                ,ContractCodeAdjust
                ,ContractCodeAdjust1
                ,ContractCodeAdjust2
                ,ContractCodeAdjust3
                ,ContractCodeAdjust4
                ,ContractCodeAdjust5
                ,ContractCodeUncommit
                ,ContractCodeUncommit1
                ,ContractCodeUncommit2
                ,ContractCodeUncommit3
                ,ContractCodeUncommit4
                ,ContractCodeUncommit5
                ,ContractCodeSaveOR
                ,ContractCodeSaveOR1
                ,ContractCodeSaveOR2
                ,ContractCodeSaveOR3
                ,ContractCodeSaveOR4
                ,ContractCodeSaveOR5
                )

basically I need the returned recordset to look like this:

Contract Code | Contract Budget | Contract Adjust | Contract Uncommit | Contract SaveOR | Pro_ID | ...
ContractCode    10.00             xxxx
ContractCode1
ContractCode2

etc…

Only if the COntractCode columns have data in them.

How do I do this?

  • 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-13T09:44:00+00:00Added an answer on June 13, 2026 at 9:44 am

    You can use union all to do it.

    select 'ContractCode' as ContractCodeType, ContractCode, ContractCodeBudget, ...
    from CO_ComapnyInformation
    
    union all
    
    select 'ContractCode1' as ContractCodeType, ContractCode1, ContractCodeBudget1, ...
    from CO_ComapnyInformation
    
    ...
    

    Maybe you don’t need that first column (ContractCodeType), it’s just so you can know from which set of values the row came from.

    Ideally though, if those fields store the same type of information, it’s better to have a simpler table only with one set of fields. You can start with a view on top of it (that’s basically the union code above), and refactor your application in small steps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table with many columns. Is there sql that will update
I'm using SQL-Server 2005. I have table with many columns, rows i select have
I have a SQL table containing customer information (we'll call it CustomerDB ), including
I have an sql table containing the gps coordinates of a device, updated every
I have a SQL table in which some columns, when viewed in SQL Server
I have a SQL table tablex with 3 columns(A, B ,C ). The following
I have a SQL table where in each row I store the country and
I have a sql table which has five columns Count1 float Count2 float Total
I have a SQL table (Trade Mapping) with the following columns: BTF_TRADE_MAPPING_KEY int BTF_SYSTEM_CODE
i have a mysql db, and i have one table which has many columns

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.