• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Looking for a shortcut to write some queries!

Kntx

Platinum Member
Here's my situation.

I have a data warehouse. It gets loaded with data from time to time. The design of the warehouse is such that when it is loaded, all previous data is wiped out.

Without telling a really long story I need to retain old data to use as a weapon against my enemies.

Anywho... what I've done is created a database whose tables are structural duplicates of some tables from the warehouse with a time dimension added. When the warehouse is load is complete I do a select insert into my historic database (with the time of the load on each record).

What I want to do is created a query that will identify differences between the current warehouse data and data in my historic database based on a specific date / time.

It's simple enough to write something like...

select * from currentdata C
inner join historicdata H ON C.ID = H.ID
where NOT C.column1 = H.column1 AND
...
NOT C.column104 = H.column104 AND
H.LoadDate = @somedate;

I am curious if there is another way to accomplish this without having to specify each column in the query?? These tables have hundreds of columns so it's kind of a pain. If it comes down to it I?ll write a little console app to create the query but am interested in other approaches before I make the plunge.
 
hmm thats a tough one.

I know this doesnt solve your problem, but I question the design of any table that has 100+ columns. Database tables are meant to grow vertically, not horizontally.

But anyways, ask over at http://www.tek-tips.com - they have a SQL forum with lots of very smart DBA's
 
Ya, it's a disgusting database. The bane of my existence actually. Not because of the 100's of columns though, they all have a purpose.
 
RedGate SQL Data Copmare will do this - it will let you select 2 databases and show you and missing/different rows. Its not free though, and not sure of the compatability with databases - i use it with MSSQL.
 
I didnt think of this yesterday, but used something similar to this before, you can use the syscolumns table. Query it to get the columns of your table, then concantenate a string together along with the rest of your query, then run the query by using the exec command.
 
just came across this article today, had no idea this tool existed in MS SQL 2k5

http://www.microsoft.com/techn...ctice/gems-top-10.mspx

TableDiff.exe

? Table Difference tool allows you to discover and reconcile differences between a source and destination table or a view. Tablediff Utility can report differences on schema and data. The most popular feature of tablediff is the fact that it can generate a script that you can run on the destination that will reconcile differences between the tables. TableDiff.exe takes 2 sets of input;

? Connectivity - Provide source and destination objects and connectivity information.

? Compare Options - Select one of the compare options

? Compare schemas: Regular or Strict

? Compare using Rowcounts, Hashes or Column comparisons

? Generate difference scripts with I/U/D statements to synchronize destination to the source.

TableDiff was intended for replication but can easily apply to any scenario where you need to compare data and schema.

You can find more information about command line utilities and the Tablediff Utility in Books Online for SQL Server 2005.
 
Back
Top