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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:29:47+00:00 2026-05-17T16:29:47+00:00

Simple concept we are basically doing some auditing, comparing what came in, and what

  • 0

Simple concept we are basically doing some auditing, comparing what came in, and what actually happened during processing. I am looking for a better way to execute a query that can do side by side table comparisons with columns that are slightly differnt in name and potentialy type.

DB Layout:

Table (* is the join condition)

Log (Un-altered data record.)
– LogID
– RecordID*
– Name
– Date
– Address
– Products
– etc.

Audit (post processing record)
– CardID*
– CarName
– DeploymentDate
– ShippingAddress
– Options
– etc.

For example this would work if you look past the annoying complexity to write, and performance issues.

The query just joins the left and right and selects them as strings. Showing each field matched up.

select 
  cast(log.RecordID as varchar(40)) + '=' + cast(audit.CardID as varchar(40),
  log.Name+ '=' + audit.Name ,
  cast(log.Date as varchar(40)) + '=' + cast(audit.DeploymentDate as varchar(40), 
  log.Address + '=' + audit.ShippingAddress,
  log.Products+ '=' + audit.Options
  --etc
from Audit audit, Log log
  where audit.CardID=log.RecordId

Which would output something like:

1=1 Test=TestName 11/09/2009=11/10/2009 null=My Address null=Wheels

This works but is extremely annoying to build. Another thing I thought of was to just alias the columns, union the two tables, and order them so they would be in list form. This would allow me to see the column comparisons. This comes with the obvious overhead of the union all.

ie:

Log 1 Test 11/09/2009 null, null
Audit 1 TestName 11/10/2009 My Address Wheels

Any suggestions on a better way to audit this data?

Let me know what other questions you may have.

Additional notes. We are going to want to reduce the unimportant information so in some cases we might null the column if they are equal (but i know its too slow)

  case when log.[Name]<>audit.[CarName] then (log.[Name] + '!=' + audit.[CarName]) else null end

or if we are doing the second way

  nullif(log.[Name], audit.[CarName]) as [Name]
  ,nullif(audit.[CarName], log.[Name]) as [Name]
  • 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-17T16:29:47+00:00Added an answer on May 17, 2026 at 4:29 pm

    I’ve found the routine given here by Jeff Smith to be helpful for doing table comparisons in the past. This might at least give you a good base to start from. The code given on that link is:

    CREATE PROCEDURE CompareTables(@table1 varchar(100), 
        @table2 Varchar(100), @T1ColumnList varchar(1000),
        @T2ColumnList varchar(1000) = '')
    AS
    
    -- Table1, Table2 are the tables or views to compare.
    -- T1ColumnList is the list of columns to compare, from table1.
    -- Just list them comma-separated, like in a GROUP BY clause.
    -- If T2ColumnList is not specified, it is assumed to be the same
    -- as T1ColumnList.  Otherwise, list the columns of Table2 in
    -- the same order as the columns in table1 that you wish to compare.
    --
    -- The result is all records from either table that do NOT match
    -- the other table, along with which table the record is from.
    
    declare @SQL varchar(8000);
    
    IF @t2ColumnList = '' SET @T2ColumnList = @T1ColumnList
    
    set @SQL = 'SELECT ''' + @table1 + ''' AS TableName, ' + @t1ColumnList +
     ' FROM ' + @Table1 + ' UNION ALL SELECT ''' + @table2 + ''' As TableName, ' +
     @t2ColumnList + ' FROM ' + @Table2
    
    set @SQL = 'SELECT Max(TableName) as TableName, ' + @t1ColumnList +
     ' FROM (' + @SQL + ') A GROUP BY ' + @t1ColumnList + 
     ' HAVING COUNT(*) = 1'
    
    exec ( @SQL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to pull some information from my tnsnames file using regex. I
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
This is beyond both making sense and my control. That being said here is
I notice in several API's, that you may create a struct which is used
My question is about memory use and objects in actionscript 2. If I have

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.