Professional Documents
Culture Documents
--**************************************
--
-- Name: Eliminate duplicates
-- Description:To elminate duplicates fr
-- om results from table in which version h
-- istory exists so you have the most curre
-- nt data only output to screen.
-- By: James Travis
--
-- Assumes:In SQL you can use subqueries
-- to build a result of data which you can
-- join back to the table. The subquery ac
-- ts as a base line of key values to make
-- duplicates disappear while still allowin
-- g verions of preiovus data to exist in t
-- he same table.
--
-- Assume you have a situation like this
-- .
-- Your company has a list of products t
-- hat occasionally changes but you want to
-- keep the previous price. They want to c
-- harge the current rate while still havin
-- g the previous rate in the same table. T
-- hey also want to be able to print a repo
-- rt which list all products current price
-- .
--
-- Our table looks like this:
--
-- Name: ProdPrice
--
-- Col1: ProdID
-- Col2: EffDate
-- Col3: Price
--
-- Col1 and 2 are the Clustered Primary
-- key so we can keep products together in
-- order of their effdate when price change
-- d. This is ideal in a product environmen
-- t as you want to access the products mos
-- t current price as fast as possible.
--
--
--
ProdPrice.EffDate != CurrData.EffDate