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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:39:05+00:00 2026-05-10T19:39:05+00:00

I have a table of data, and I allow people to add meta data

  • 0

I have a table of data, and I allow people to add meta data to that table.

I give them an interface that allows them to treat it as though they’re adding extra columns to the table their data is stored in, but I’m actually storing the data in another table.

Data Table    DataID    Data  Meta Table    DataID    MetaName    MetaData 

So if they wanted a table that stored the data, the date, and a name, then I’d have the data in the data table, and the word ‘Date’ in metaname, and the date in MetaData, and another row in the meta table with ‘Name’ in metaname and the name in metadata.

I now need a query that takes the information from these tables and presents it as though coming from a single table with the two additional columns ‘Data’ and ‘Name’ so to the customer it would look like there’s a single table with their custom columns:

MyTable    Data    Date    Name 

Or, in other words, how do I go from here:

Data Table    DataID        Data    1             Testing!    2             Hello, World!  Meta Table    DataID        MetaName         MetaData    1             Date             20081020    1             Name             adavis    2             Date             20081019    2             Name             mdavis 

To here:

MyTable    Data          Date             Name    Testing!      20081020         adavis    Hello, World! 20081019         mdavis 

Years ago when I did this in MySQL using PHP, I did two queries, the first to get the extra meta data, the second to join them all together. I’m hoping that modern databases have alternate methods of dealing with this.

Related to option 3 of this question.

-Adam

  • 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. 2026-05-10T19:39:06+00:00Added an answer on May 10, 2026 at 7:39 pm

    You want to pivot each of your name-value pair rows in the MyTable… Try this sql:

    DECLARE @Data   TABLE (     DataID      INT IDENTITY(1,1)   PRIMARY KEY,     Data        VARCHAR(MAX) )  DECLARE @Meta   TABLE (     DataID      INT ,     MetaName    VARCHAR(MAX),     MetaData    VARCHAR(MAX) )  INSERT INTO @Data SELECT 'Data'  INSERT INTO @Meta SELECT 1, 'Date', CAST(GetDate() as VARCHAR(20)) UNION SELECT 1, 'Name', 'Joe Test'  SELECT * FROM @Data  SELECT * FROM @Meta  SELECT      D.DataID,     D.Data,     MAX(CASE MetaName WHEN 'Date' THEN MetaData ELSE NULL END) as Date,     MAX(CASE MetaName WHEN 'Name' THEN MetaData ELSE NULL END) as Name FROM     @Meta M JOIN    @Data D     ON M.DataID = D.DataID   GROUP BY     D.DataID,     D.Data 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of data that I need to dynamically add a column
I'm using ASP.Net/C# and I have a form that allows people to add information
I have table of data that is sorted as follows: Item | Sample |
I have a table containing data about some users. Many of them use our
I have a table of data which represents a series of events that persons
I need a user interface that allows users to sort a table according to
I have table in data base name train delay, with columns train number(int), DelayTime(int),
I do have a table data as shown below: <td> <label for=title>Title : </label>
My table have data structure like this cate_id task_id date_start date_end other 34 14
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work

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.