Ok heres the problem, I have 5 different tables created by god knows who each with different data, an dI need to merge them in a single table.
My first problem is that each day have a time stamp but I only need the last records add each day, so how can I search each day for the last records and save them on a new table, most of this tables are big around 400 million records.
The following query return me the last register, but I need to search for each day, last register (as someone mess with the job and it did it each 15 minutes for each day making a lot of duplicate data).
The range of the days is from 1 of january 2006 to current day (depending on the table) as some go up to 2008.
So far I have this.
SELECT * FROM [PDP].[dbo].[Existencia_WH_PRISM_BACKUP]
WHERE dExD_Fecha = (SELECT MAX(dExD_Fecha)
FROM dbo.Existencia_WH_PRISM_BACKUP)
This bring me a result like
NombreEntidad dExD_Fecha LDWHSE LDLOCN LDRESC LDLOTN LDGRDE LDLOCQ LDUMSR LDRSCL LDRSSC LDQRUM LDRCUM LDPOTF LDREVL LDCLCD LDOOIN LDAVPL LDOHIN LDDVIN LDDWIP LDQYRM LDQYRS LDDLRC LDTLRC LDTRAN LDFIFO LDETD LDETT LDEXPD LDVNNO LDPOSQ LDDTMT LDACTP LDZONE LDAVPT LDRTND LDCDDT LDLSQY LDAGE1 LDAGE2 LDAGE3 LDAGE4 LDAGE5 LDAMIR LDRCLS LDPTAW LDCSPK LDQYOU LDBLNK
HDZALM 2010-05-28 12:01:00.000 1T A04 405120 K0146 864.000000 CJ PT 40 864.000000 CJ 0.000000 STOC N 2 Y Y N 0.000000 0.000000 1100527 75934 6659304 1100527 1100527 61504 1110527 5 1100527 N A Y 0.000000 9999999 9999999 9999999 9999999 9999999 N Y Y N 0.000000
HDZALM 2010-05-28 12:01:00.000 1T A04 405120 K0147 1944.000000 CJ PT 40 1944.000000 CJ 0.000000 STOC N 2 Y Y N 0.000000 0.000000 1100527 120112 6665777 1100527 1100527 120051 1110527 5 1100527 N A Y 0.000000 9999999 9999999 9999999 9999999 9999999 N Y Y N 0.000000
HDZALM 2010-05-28 12:01:00.000 1T A05 405120 K0146 2052.000000 CJ PT 40 2052.000000 CJ 0.000000 STOC N 2 Y Y N 0.000000 0.000000 1100527 54402 6658261 1100527 1100527 54146 1110527 5 1100527 N A Y 0.000000 9999999 9999999 9999999 9999999 9999999 N Y Y N 0.000000
HDZALM 2010-05-28 12:01:00.000 1T A05 405120 K0147 2160.000000 CJ PT 40 2160.000000 CJ 0.000000 STOC N 2 Y Y N 0.000000 0.000000 1100527 153911 6671885 1100527 1100527 153714 1110527 5 1100527 N A Y 0.000000 9999999 9999999 9999999 9999999 9999999 N Y Y N 0.000000
HDZALM 2010-05-28 12:01:00.000 1T A06 405120 K0146 4212.000000 CJ PT 40 4212.000000 CJ 0.000000 STOC N 2 Y Y N 0.000000 0.000000 1100527 43743 6657177 1100527 1100527 43625 1110527 5 1100526 N A Y 0.000000 9999999 9999999 9999999 9999999 9999999 N Y Y N 0.000000