title: SQL Server 2000 - Breaking out of a loop
body: <p>I am not good at SQL Server 2000. I have a comma-delimited list of ids. I need to see if that ID exists in a table. If it does, I want to break out of the loop with that ID saved in a variable that I can use in my stored procedure. This is what I am trying right now:</p>
  
  <pre><code>DECLARE @coreID INT
  SET @coreID=NULL
  
  DECLARE @itemID NVARCHAR(50)
  DECLARE itemCursor CURSOR LOCAL FAST_FORWARD FOR
    SELECT [String] AS 'itemID' FROM dbo.SplitListIntoTable(@myIDs)
  
  OPEN itemCursor
  FETCH NEXT FROM itemCursor INTO @itemID
    WHILE @@FETCH_STATUS = 0 BEGIN
  
    -- If @itemID EXISTS IN MyTable set @coreID=@itemID and Break. How do I do this?
  
    FETCH NEXT FROM itemCursor INTO @itemID
  END
  
  CLOSE itemCursor
  DEALLOCATE itemCursor
  </code></pre>
  
  <p>Thank you!</p>