Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

field differences

Posted on 2010-11-24
1
Medium Priority
?
334 Views
Last Modified: 2012-05-10
I have two tables one that has new data monthly and the other a back up of it. I have renamed last months, how do i create a query that will tell me if any data in any field changed  value?

so [currentmonth].[field1] =[lastmonthsbackup].[field1] no change
 [currentmonth].[field2]<>[lastmonthsbackup].[field2] data changed so row returned

the two tables are obviously identicle in structure.
SELECT SMMT.[DVLA CODE], SMMT.[MVRIS MAKE CODE], SMMT.[MVRIS MODEL CODE], SMMT.[MVRIS CODE], SMMT.[VEHICLE CATEGORY CODE], SMMT.[VEHICLE CATEGORY DESCRIPTION], SMMT.[INTRO DATE], SMMT.MARQUE, SMMT.[MODEL RANGE], SMMT.[RANGE SERIES], SMMT.[MODEL YEAR], SMMT.VARIANT, SMMT.CC, SMMT.[NOM CC], SMMT.DOORS, SMMT.[BODY TYPE], SMMT.TRANSMISSION, SMMT.FUEL, SMMT.ASPIRATION, SMMT.[COUNTRY OF ORIGIN], SMMT.[DRIVE TYPE], SMMT.[ENGINE LOCATION], SMMT.[DRIVING AXLE], SMMT.[FORWARD GEARS], SMMT.SEATS, SMMT.[ENGINE MAKE], SMMT.[ENGINE MODEL], SMMT.[ENGINE CONFIGURATION], SMMT.[FUEL DELIVERY], SMMT.BORE, SMMT.STROKE, SMMT.[NO CYLINDERS], SMMT.[VALVES PER CYLINDER], SMMT.[VALVE GEAR], SMMT.[MAIN FUEL], SMMT.[POWER KW], SMMT.[MKT BHP], SMMT.[CALC BHP], SMMT.[POWER RPM], SMMT.[TORQUE NM], SMMT.[TORQUE LBFT], SMMT.[TORQUE RPM], SMMT.[MAX SPEED MPH], SMMT.[MAX SPD KPH], SMMT.[ACCELERATION 0-100 KPH], SMMT.[URBAN COLD MPG], SMMT.[URBAN COLD LITRE / 100 KMS], SMMT.[EXTRA URBAN MPG], SMMT.[EXTRA URBAN LITRE / 100 KMS], SMMT.[COMBINED MPG], SMMT.[COMBINED LITRE / 100 KMS], SMMT.CO2, SMMT.LENGTH, SMMT.WIDTH, SMMT.HEIGHT, SMMT.WHEELBASE, SMMT.[MARKET SEGMENT], SMMT.GVW, SMMT.PAYLOAD, SMMT.[UNLADEN WEIGHT], SMMT.[KERB WEIGHT MIN], SMMT.[KERB WEIGHT MAX], SMMT.[EURO STATUS], SMMT.[INSURANCE GROUP], SMMT.[Ref ID], SMMT.MARKET, SMMT.[TERMINATION DATE], SMMT.VehicleCountByMvris, SMMT.Notes, SMMT.[VIN stem], SMMT.RelatedMvrisCode, SMMT.[CAB TYPE], SMMT.[LOADSPACE LENGTH], SMMT.[VAN ROOF CONFIG], SMMT.[WHEELBASE TYPE], SMMT.NCAP_Adult, SMMT.NCAP_Child, SMMT.NCAP_Pedestrian, SMMT.NCAP_SafetyAssist, SMMT.NCAP_Overall, SMMT.Checked, SMMT.CountSinceRefresh, SMMT.DPF, SMMT.CalcNomCC, SMMT.[MCRIS Make Code], SMMT.[MCRIS Model Code]
FROM SMMT INNER JOIN SMMT_Previous ON SMMT.[MVRIS CODE] = SMMT_Previous.[MVRIS CODE];

Open in new window

0
Comment
Question by:PeterBaileyUk
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 34205141
Add a WHERE condition comparing all the fields which you care about. Check that they are not equal to each other and OR each set of fields together. Pseudocode:
WHERE t1.f1 <> t2.f1 OR t1.f2 <> t2.f2 OR t1.f3 <> t2.f3

Open in new window

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question