declare @email nvarchar(20), @InitialAmount int, @GiftCardTypeID int SET @InitialAmount=25 /*change this to your preferred initial amount*/ SET @GiftCardTypeID=101 /*101=EMAIL, 102=Certificate, 100=Physical*/ /*select specific customers to be given GCs*/ declare tb_cur cursor for select distinct cust.email from dbo.customer cust, dbo.Orders Ord where cust.CustomerID=Ord.CustomerID and ord.OrderDate >= '10/24/2011' and ord.OrderDate <= '12/31/2011' /* retrieve customers that placed orders within these dates */ open tb_cur fetch next from tb_cur into @email /*loop through the selected email and insert one GC per email into giftcard table*/ while @@fetch_status = 0 begin insert dbo.GiftCard(GiftCardGUID, SerialNumber, PurchasedByCustomerID, OrderNumber, ShoppingCartRecID, ProductID, VariantID, InitialAmount, Balance, ExpirationDate, GiftCardTypeID, EMailName, EMailTo, EMailMessage, ValidForCustomers, ValidForProducts, ValidForManufacturers, ValidForCategories, ValidForSections, DisabledByAdministrator, ExtensionData, CreatedOn) values ( newid(), newid(), 0, 0, 0, 0, 0, @InitialAmount, @InitialAmount, dateadd(yy,1,getdate()), @GiftCardTypeID, '', @email, '', '', '', '', '', '', 0, '', getdate() ) fetch next from tb_cur into @email end close tb_cur deallocate tb_cur