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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:31:11+00:00 2026-05-25T12:31:11+00:00

Imagine the following (very bad) table design in MSSQL2008R2: Table Posts: | Id (PK,

  • 0

Imagine the following (very bad) table design in MSSQL2008R2:

Table "Posts":
| Id (PK, int) | DatasourceId (PK, int) | QuotedPostIds (nvarchar(255)) | [...] 
|     1        |        1               |                               | [...] 
|     2        |        1               |           1                   | [...] 
|     2        |        2               |           1                   | [...] 
[...]
|   102322     |        2               |     123;45345;4356;76757      | [...] 

So, the column QuotedPostIds contains a semicolon-separated list of self-referencing PostIds (Kids, don’t do that at home!). Since this design is ugly as a hell, I’d like to extract the values from the QuotedPostIds table to a new n:m relationship table like this:

Desired new table "QuotedPosts":
| QuotingPostId (int) | QuotedPostId (int) | DatasourceId (int) |
|        2            |        1           |         1          |
|        2            |        1           |         2          |
[...]
|      102322         |       123          |         2          |
|      102322         |      45345         |         2          |
|      102322         |       4356         |         2          |
|      102322         |      76757         |         2          |

The primary key for this table could either be a combination of QuotingPostId, QuotedPostId and DatasourceID or an additional artificial key generated by the database.

It is worth noticing that the current Posts table contains about 6,300,000 rows but only about 285,000 of those have a value set in the QuotedPostIds column. Therefore, it might be a good idea to pre-filter those rows. In any case, I’d like to perform the normalization using internal MSSQL functionality only, if possible.

I already read other posts regarding this topic which mostly dealt with split functions but neither could I find out how exactly to create the new table and also copying the appropriate value from the Datasource column, nor how to filter the rows to touch accordingly.

Thank you!

€dit: I thought it through and finally solved the problem using an external C# program instead of internal MSSQL functionality. Since it seems that it could have been done using Mikael Eriksson’s suggestion, I will mark his post as an answer.

  • 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-05-25T12:31:11+00:00Added an answer on May 25, 2026 at 12:31 pm

    From comments you say you have a string split function that you you don’t know how to use with a table.

    The answer is to use cross apply something like this.

    select P.Id,
           S.Value
    from Posts as P
      cross apply dbo.Split(';', P.QuotedPostIds) as S
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine the following tables: create table boxes( id int, name text, ...); create table
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
Imagine the following table (called TestTable ): id somedate somevalue -- -------- --------- 45
Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products'
Imagine that I have the following two methods: void AddEvenNumbers() { for(int i=0; i<10000000;
Imagine following scenario: We have a lot of parallel development going on in several
Imagine the following class: class A { public event EventHandler AnyEvent; } You create
Imagine the following A type T has a field Company. When executing the following
Imagine the following REBOL code: foo: context [bar: 3] I now have a context
Imagine the following: you read in a string with scanf() but you only need

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.