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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:25:04+00:00 2026-05-27T00:25:04+00:00

We have a simple table (an audit log) that our (3rd-party) product fills with

  • 0

We have a simple table (an audit log) that our (3rd-party) product fills with data. The problem is that the data appears to be an XML serialisation of data, stored in a varchar(max()) column.

CREATE TABLE Audit (
    AuditID int IDENTITY, 
    AuditData nvarchar(max) NULL
)

The data AuditData then looks a bit like this:

<DELETED customerId="89" 
    username="alice" 
    firstname="Alice" 
    lastname="WTF" 
    field1="..." 
    field2="..." 
    fieldn="..."
/>

Is there any sensible way of getting at this data from SQL queries? For example let us say I want to get all audit records where the customerId is 89.

I don’t want to have to resort to string mangling if I can possibly help it!

-- This is bad:
SELECT AuditID, AuditData
FROM Audit 
WHERE AuditData LIKE '%customerId="89"%'
  • 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-27T00:25:05+00:00Added an answer on May 27, 2026 at 12:25 am

    It would easier/faster if AuditData was an XML column but you can cast it in the query.

    select AuditID, AuditData
    from Audit
    where cast(AuditData as xml).value('(/DELETED/@customerId)[1]', 'int') = 89
    

    Note: This requires that AuditData column contains valid XML for all rows in the table. (NULL is ok) and SQL Server 2005 or higher.

    If you want to filter on customerId regardless of the root node name you can use this instead.

    select AuditID, AuditData
    from Audit
    where cast(AuditData as xml).value('(/*/@customerId)[1]', 'int') = 89
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My memory is failing me. I have a simple audit log table based on
I have a simple table that prints our the list of videos and plays
I have a simple table that has this structure: <table> <thead> <tr> <td>Some info</td>
I have a simple table (lets call it Table1) that has a NVARCHAR field
I have simple table that has about 80 rows, which I populate dynamically using
I have a simple table that contains unique identifiers and a counter value for
I have simple table with two columns: id INTEGER as a key, and data
I have a simple table that is used to record events against specific visits:
i have a simple table data like: date | Jenna | Tom | Robin
I have a simple table that contains 3 rows: a short text, its own

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.