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

  • Home
  • SEARCH
  • 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 346873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:13:04+00:00 2026-05-12T11:13:04+00:00

I am trying to solve this problem. I have a series of SELECT statements

  • 0

I am trying to solve this problem.

I have a series of SELECT statements like below.

SELECT Name FROM Table1 WHERE Name LIKE '%Tom%'

SELECT Name From Table2 WHERE Name LIKE '%Tom%'

.
.
.

SELECT Name FROM Table10 WHERE Name Like '%Tom%'

Without using IF ELSE statements, is there any way I can terminate this script halfway and return the selection as soon as something is selected without having to execute the rest of the SELECT statements?

Cheers.

  • 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-12T11:13:05+00:00Added an answer on May 12, 2026 at 11:13 am

    Instead of an IF..ELSE, you could check the value of @@Rowcount (or some other criteria) after each select, and either return or goto a label at the end of the script if the value is greater than 0. It will still be a lot of conditional checks, but the nesting won’t be as difficult to manage.

    e.g.

    declare @vals table (id int)
    Declare @rc int
    Insert into @vals (id) values (1)
    Select * from @vals
    set @rc = @@ROWCOUNT
    if @rc <> 0
    Begin
        Print 'Exiting Early'
        return 
    End
    Select * from @vals
    Select * from @vals
    Select * from @vals
    Select * from @vals
    Select * from @vals
    

    Or

    declare @vals table (id int)
    Declare @rc int
    Insert into @vals (id) values (1)
    
    Select * from @vals
    set @rc = @@ROWCOUNT
    if @rc <> 0
    Begin
        Print 'Exiting Early'
        GOTO EarlyExit 
    End
    
    
    Select * from @vals
    Select * from @vals
    Select * from @vals
    Select * from @vals
    Select * from @vals
    
    
    EarlyExit:
        Print 'We are done here'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to solve this problem for a while, but couldn't with
I'm trying to solve this problem for a long time. I have 2 forms,
Trying to solve this problem . I would like to learn how the bootstrapper
I have been trying to solve this problem for a while, could not find
I have been trying to solve this problem the whole day: How do I
I am trying to solve this problem : https://www.spoj.pl/problems/CERC07S/ I have identified that i
I have been trying to solve this problem all day, I googled a lot,
I have been trying to solve this problem for hours (searched here as well
I have exhausted all avenues in trying to solve this problem and in the
I have been trying to solve this problem for three days now, it's really

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.