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 7703081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:22:39+00:00 2026-05-31T23:22:39+00:00

I need to run a loop in SQL. Google this is a little hard

  • 0

I need to run a loop in SQL. Google this is a little hard for some odd reason. In SQL Server I just put this is in the query editor in SQL Server Managment Studio

DECLARE @z_start INT
SET @z_start = 0
DECLARE @z_end INT
SET @z_end = 0

WHILE (@z_start <= 14) BEGIN
    IF(@z_start != 0 AND @z_end != 14)
        WHILE (@z_end <= 14) BEGIN
            INSERT INTO [campusMap].[dbo].[zoom_levels] ([zoom_start],[zoom_end]) VALUES (@z_start,@z_end)
            SET @z_end = @z_end + 1
        END
        SET @z_start = @z_start + 1
    END
END

All I want to do is to set the zoom_start and zoom_end so (0,0) to (14,14) skipping only (0,14) as that is already in the table.

I think I’m close. Anyone know where it’s off? Thank you.
Cheers -Jeremy

  • 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-31T23:22:40+00:00Added an answer on May 31, 2026 at 11:22 pm

    Instead of doing a nested loop and inserted each row at a time, you can use a CTE (Or a pre-existing numbers table) and add all the rows you need at once:

    ;WITH Numbers (Number) AS 
    (
        SELECT 0 
        UNION ALL
        SELECT 1 + Number FROM Numbers 
        WHERE 1 + Number <= 14
    )
    INSERT INTO [campusMap].[dbo].[zoom_levels] ([zoom_start],[zoom_end])
    SELECT n1.Number, n2.Number 
    FROM
        Numbers n1 CROSS JOIN
        Numbers n2
    WHERE
        NOT (n1.Number = 0 AND n2.Number = 14)
    

    Set-based operations in SQL are usually cleaner and easier to understand than procedural, row-by-row approaches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to run a stored procedure on SQL Server, using LINQ, and throw
I've got a SQL Server 2000 db. I need to run the following cursor
I need to run a PHP loop for a total of 100, 000 times
I need to run a RLIKE query on a database mmoved from MySQL to
I have the need to run a .bat file to run a SQL command
So, I have a huge query that I need to run on an Access
I need to run a couple of relatively simple SQL update statements to update
I am using this awesome code from @Richard aka cyberkiwi to run a query
i need run code that will create a database and populate tables. i am
I need run ts:reindex when smth add in model or destroy from model. How

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.