narsil/Sql/2016.04.11 Happy Hour Inventory Import.sql
tanshu 20eac3c216 Refactor: Instead of a concept of Price/FullPrice, happy hour is now a checkbox in the product.
This needed major refactor in all parts dealing with product or inventory.
2016-04-11 12:31:52 +05:30

26 lines
880 B
Transact-SQL

declare @id uniqueidentifier
declare @name nvarchar(255)
declare @units nvarchar(255)
declare @price decimal(19,5)
declare @org uniqueidentifier
declare @c int
DECLARE db_cursor CURSOR FOR
select ProductID, Name, Units, price from products where name like 'H h %' and hashappyhour = 1
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @id, @name, @units, @price
WHILE @@FETCH_STATUS = 0
BEGIN
select @c = count(*) from products where 'H H ' + name = @name and units = @units
if @c = 1
BEGIN
select @org = productid from products where 'H H ' + name = @name and units = @units
update inventories set productid = @org, ishappyhour = 1 where productid = @id
delete from products where productid = @id
update products set hashappyhour = 1 where productid = @org
END
FETCH NEXT FROM db_cursor INTO @id, @name, @units, @price
END
CLOSE db_cursor
DEALLOCATE db_cursor