Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 645945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:33:29+00:00 2026-05-13T21:33:29+00:00

I am not good at SQL Server 2000. I have a comma-delimited list of

  • 0

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:

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

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:33:30+00:00Added an answer on May 13, 2026 at 9:33 pm

    Ideally, you shouldn’t use a cursor as performance won’t be great. If you can do it as a set-based statement, do that instead, maybe like this:

    SELECT TOP 1 @CoreID = [String] 
    FROM dbo.SplitListIntoTable(@myIDs) x
        JOIN MyTable t ON x.[String] = t.ID
    

    However, if you have a real reason to use a cursor, you can use the BREAK statement to break out of a WHILE loop

    e.g.

    WHILE @@FETCH_STATUS = 0 
        BEGIN
            IF EXISTS(SELECT * FROM MyTable WHERE Id = @ItemID)
                BEGIN
                    SET @CoreId = @ItemId
                    BREAK
                END        
    
            FETCH NEXT FROM itemCursor INTO @itemID
        END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're using SQL Server 2000 Query Analyser, and one issue we have is that
I have a legacy SQL Server 2000 database that has one column that has
I have a table with CreateDate datetime field default(getdate()) that does not have any
I'm interested in speed, not good looking code, that is why I'm using array
As you can see here and here I'm not a good friend of asp.net
I'm investigating the possibility of upgrading our SQL Server from SQL Server 2000 to
I'm not good with JavaScript, and this is Google's code. I'm getting a object
Honestly I'm very bad at CSS and not good at dealing with color /
Pretty straightforward stuff, here -- I'm just not good enough with mysql to understand
I am learning to use the Dvorak keyboad layout, but I am not good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.