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 9297673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:07:58+00:00 2026-06-18T22:07:58+00:00

I have a table formatted like the one below, i want to split it

  • 0

I have a table formatted like the one below, i want to split it up so theres a column for month and year ie. January 2014 then another column for cost. So effectively each row would be split into 12 different rows, but i cant for the life of me figure out how to approach it. Any help would be greatly appreciated

    CREATE TABLE dbo.Line14(
    ItemID int IDENTITY(1,1) NOT NULL,
    Detail nvarchar(max) NULL,
    Type nvarchar(255) NULL,
    Cat nvarchar(255) NULL,
    Jan_14 money NULL,
    Feb_14 money NULL,
    Mar_14 money NULL,
    Apr_14 money NULL,
    May_14 money NULL,
    Jun_14 money NULL,
    Jul_14 money NULL,
    Aug_14 money NULL,
    Sep_14 money NULL,
    Oct_14 money NULL,
    Nov_14 money NULL,
    Dec_14 money NULL
) ON PRIMARY TEXTIMAGE_ON PRIMARY
GO 
  • 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-18T22:07:59+00:00Added an answer on June 18, 2026 at 10:07 pm

    You should be able to use the UNPIVOT function which converts the data from columns into rows:

    select itemid,
      detail,
      type,
      cat,
      Month,
      2014 as Year,
      value
    from Line14
    unpivot
    (
      value
      for Month in (Jan_14, Feb_14, Mar_14, Apr_14,
                    May_14, Jun_14, Jul_14, Aug_14,
                    Sep_14, Oct_14, Nov_14, Dec_14)
    ) unpiv
    

    See SQL Fiddle with Demo.

    The result would be similar to this:

    | ITEMID | DETAIL | TYPE |  CAT |  MONTH | YEAR | VALUE |
    ---------------------------------------------------------
    |      1 |   Test |    C | blah | Jan_14 | 2014 |    10 |
    |      1 |   Test |    C | blah | Feb_14 | 2014 |    12 |
    |      1 |   Test |    C | blah | Mar_14 | 2014 |    45 |
    |      1 |   Test |    C | blah | Apr_14 | 2014 |    56 |
    |      1 |   Test |    C | blah | May_14 | 2014 |    89 |
    |      1 |   Test |    C | blah | Jun_14 | 2014 |    78 |
    |      1 |   Test |    C | blah | Jul_14 | 2014 |    96 |
    |      1 |   Test |    C | blah | Aug_14 | 2014 |    35 |
    |      1 |   Test |    C | blah | Sep_14 | 2014 |    55 |
    |      1 |   Test |    C | blah | Oct_14 | 2014 |    30 |
    |      1 |   Test |    C | blah | Nov_14 | 2014 |    99 |
    |      1 |   Test |    C | blah | Dec_14 | 2014 |   120 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one Date column, formatted '17/03/2012'. I would like to be able select
In SQLExpress, I have a table that contains a datetime-column. It is formatted like
I have a table with a column ancestry holding a list of ancestors formatted
I have a table full of data, where one column is full of different
I have two functions, one that creates a table like so: function return_formatted_results(result_no,addy,title,own_comment) {
I have a table formatted html query to bind datas within a div actually.
I have a data Table with numbers formatted according to the current regional settings.
I have table and this table contain result column with some entries. I just
I have two long list, one from a log file that contains lines formatted
I try to use print.xtable add.to.row to get table formatted like this: sports share

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.