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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:19:52+00:00 2026-06-15T20:19:52+00:00

We have an auditing system which logs all the changes that occur in all

  • 0

We have an auditing system which logs all the changes that occur in all the system tables. Basically, this is how the AuditLog table looks like:

enter image description here

Currently I am creating a couple of sql views to query different kind information. Everything is ok except for one point. If you take a look at the image again, you will see I have a SubscriptionMetadata table which is a key-value pairs table with 2 fields (MetaName and MetaValue). What the immage shows is that the subscription has a new watermark which value is ‘Licensed copy: Fullname, Company, V…’.

What I need is transform, in my view, these two rows in just one with the following form:

41 - Insert - SubscriptionMetadata - 2012-10-19 - 53DA4XXXXXX - Watermark -  Licensed copy: Fullname, Company, V...

I really cannot imagine how I can do it or search for it neither.

There is another problem (I think), these rows comes always in that order: MetaName first and then MetaValue. That´s the only way to know they are related.

Could you help me, please?

  • 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-15T20:19:53+00:00Added an answer on June 15, 2026 at 8:19 pm

    While I cannot see your full table structure you can transform the data the following way. Both of these solutions will place the data in separate columns:

    ;with data(id, [action], [type], [date], [col], metatype, value) as
    (
        select 41, 'Insert', 'SubscriptionMetaData', '2012-10-19', '53DA4XXX','Metaname', 'Watermark'
        union all
        select 41, 'Insert', 'SubscriptionMetaData', '2012-10-19', '53DA4XXX','MetaValue', 'Licensed copy: Fullname, Company'
    ) 
    select id, action, type, date, col,
        MAX(case when metatype = 'Metaname' then value end) Name,
        MAX(case when metatype = 'MetaValue' then value end) Value
    from data
    group by id, action, type, date, col
    

    See SQL Fiddle with Demo

    Or you can use a PIVOT on the data to get the same result:

    ;with data(id, [action], [type], [date], [col], metatype, value) as
    (
        select 41, 'Insert', 'SubscriptionMetaData', '2012-10-19', '53DA4XXX','Metaname', 'Watermark'
        union all
        select 41, 'Insert', 'SubscriptionMetaData', '2012-10-19', '53DA4XXX','MetaValue', 'Licensed copy: Fullname, Company'
    ) 
    select *
    from
    (
        select id, [action], [type], [date], [col], metatype, value
        from data
    ) src
    pivot
    (
        max(value)
        for metatype in (Metaname, MetaValue)
    ) piv
    

    See SQL Fiddle with Demo

    Both produce the same result:

    | ID | ACTION |                 TYPE |       DATE |      COL |      NAME |                            VALUE |
    -------------------------------------------------------------------------------------------------------------
    | 41 | Insert | SubscriptionMetaData | 2012-10-19 | 53DA4XXX | Watermark | Licensed copy: Fullname, Company |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called Card that I am auditing with a shadow table
I have a table in my SQL Server DB that holds auditing information for
I have two auditing tables: Trip_aud and Event_aud. They were created in Envers, but
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have decided to create a new table in my database that will be
currently we have quite a chunky auditing system for objects within our application, the
I have a need to support extensive auditing capabilities for a system backing into
I have a large auditing stored procedure that prints values and runs some SELECT
I have a trigger that is used for auditing inserted, updated and deleted rows.

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.