Hi Jeff and thanks for your response. And those are excellent questions...that I wish I could answer.
This was not my script originally, and I can tell you that I know just enought about SQL to make my head hurt. But, I believe this is the Watcom SQL variety.
And I was mislead by the error dialog, the statement that was really causing the problem was the previous statement. I was trying to initialize the integer variable with value. So no it seems it's my "SET" statement that doesn't run. Here is the entire script in all it's glory.
BEGIN
DECLARE externalId int;
SET externalId = 500000; <====== This one not happy
DECLARE newItemName varchar(50);
DECLARE nextkey int;
DECLARE nextUofmKey int;
DECLARE nextXAKey int;
DECLARE gonext int;
SET gonext = 10; <====== assuming this one also not happy
While externalId < 800000
SET externalId = externalId + gonext
-- make an item
exec cbord.cbo_getnextkey 'cbo1000p_item', nextkey out
SET newItemName = 'NewLinkedItem_' + CAST(externalId AS VARCHAR(10))
INSERT INTO cbord.cbo1000p_item
(Item_intid,UnitId,KeyName,LongName,ItemTypeCode,ActivityLevel
,ConstructedFlag,TLC,updatecount,creation_date,ItemGuid,Creator
,ItemRecipeLockFlag)
VALUES
(nextkey,0,externalId,newItemName,1,9,'N',GetDate(),1,GetDate(),NEWID(),1,'N')
-- Make a uofm
exec cbord.cbo_getnextkey 'cbo1020p_ItemUofM', nextUofmKey out
INSERT INTO cbord.cbo1020p_ItemUofM
(ItemUofm_Intid,Item_intid,itemuofm_keyname,itemuofm_usage,ItemUofM_Qty,MeasureType,[Description],BasisRatio,TLC,unitid)
VALUES
(nextUofMKey,nextkey,'UofM_' + CAST(externalId AS VARCHAR(10)),'P', 1, 'B', 'unit', 1, GetDate(), 0)
-- Make an ItemXA record
exec cbord.cbo_getnextkey 'cbo1001p_itemxa', nextXAKey out
INSERT INTO cbord.cbo1001p_itemxa
(Itemxa_intid,Item_intid,srv_ShortName,UnitId,srv_itemuofm_intid,Yield,default_itemxa_intid,TLC,Yield_itemuofm_intid,purtax1flag,purtax2flag,purtax3flag,purtax4flag)
VALUES
(nextXAKey,nextkey,'SN_' + CAST(externalId AS VARCHAR(10)),0,nextUofMKey,1,nextXAKey,GetDate(),nextUofMKey,'N','N','N','N')
if (externalId >=600000 AND externalId < 700000) BEGIN SET gonext = 5 SET externalId = 700000 END
END
GO
Thanks for your help Jeff!
Tony