/* JP 20060524
   Delete all rows on dayproducts which should never have been there

   Changes
   JP 20070704 EXT: Look at new PricePerType setting
   AV 20080226 BUG: ask if field exists 
*/

If not exists(select distinct syscolumns.name from syscolumns WITH (nolock) 

  inner join sysobjects WITH (NOLOCK) ON syscolumns.id = sysobjects.id

  where sysobjects.name = 'Products' and syscolumns.name = 'PricePerType')

alter table Products add PricePerType bit


delete from productprice where productnumber in (select productnumber from products WITH (nolock) where dayproduct=1 and isnull(pricepertype,0) = 0) and roomtypenumber > 0