I am trying to run the below code to quickly update the order & order date on multiple items (the item list is larger than this, but cut it down for examples sake.) When I try to run this SQL I get an error that says Incorrect syntax near '=' Which element of this programming is throwing my error?
declare @sql varchar(8000), @count int, @item varchar(100) if object_id('tbl_Checklist') is not null drop table dbo.tbl_Checklist Create Table tbl_Checklist ( Item varchar(50), runthro int ) insert into tbl_Checklist (Item) select 'Baseball' insert into tbl_Checklist (Item) select 'Football' insert into tbl_Checklist (Item) select 'Bat' insert into tbl_Checklist (Item) select 'Hat' insert into tbl_Checklist (Item) select 'Tee' set @count = (select count(*) from tbl_Checklist) while @count > 0 begin set @item = (select top 1 item from tbl_Checklist where runthro is null) set @sql = 'Update' + @item + ' Set Ordered = ''Yes'', OrderDate = Convert(varchar(10), GetDate(), 101)' exec @sql update tbl_Checklist set runthro = 1 where item = @item set @count = @count - 1 End End