narsil/Sql/2016.04.11 Happy Hour Inventory Import.sql

26 lines
880 B
MySQL
Raw Normal View History

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