sql server - Finding large changes in consecutive numbers in database -


i have sql server db contains large amount of daily share prices of companies. goal automatize data validation goes through daily price changes of each company , notices large changes (> +/-50 % example) find errors/splits. db structure following:

ticker  date        price ameas   2010-01-03  11,20 ameas   2010-01-02  11,00 ameas   2010-01-01  10,00 knevb   2010-01-03  5,00 knevb   2010-01-02  3,50 knevb   2010-01-01  3,50 

so want script go through each ticker (ameas, knevb in case) , check ratio between each consecutive days (ameas 2010-01-02 , ameas 2010-01-01: 11.00 / 10.00 etc..), if ratio more 1.5 or less 0.5 make note.

question: kind of checks need calculations possible in database (check constraints? queries? else? if so, can point me right direction start figuring out. if no, have suggestions this?

thank in advance, lerbert

in order compare prices use lag previous record.

select * (   select      ticker,      date,      price,      lag(price) on (partition ticker order date) price_before   prices ) both_prices price > price_before * 1.5 or price < price_before * 0.5; 

you can regularly in batch of course. don't know if possible cover in trigger, however.


Comments