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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:42:36+00:00 2026-06-01T10:42:36+00:00

I am a SQL novice. My problem is I can’t find the infinite loop

  • 0

I am a SQL novice. My problem is I can’t find the infinite loop in the code below. The query just keeps executing, but I do not know why. Can anyone point out the mistake in my code?

Additional details: I’ll be running this query for 3500 entries. I know my query will probably run too slowly. So I would be interested in hearing about any faster methods as well.

Thanks in advance.

DECLARE @intCounter INT,@strNo VARCHAR(8)
DECLARE @strResult VARCHAR(12),@strResult1 VARCHAR(2),@strResult2 VARCHAR(2),@strResult3 VARCHAR(1),@strResult4 VARCHAR(1),@strResult5 VARCHAR(3),@strResult6 VARCHAR(2)
DECLARE @intDecimalValueYear INT,@intDecimalValueMonth INT,@intDecimalValueDay INT,@intDecimalValueTimer1 INT,@intDecimalValueTimer2 INT,@intDecimalValueTimer3 DECIMAL(7,2),@intCounterTemp INT
DECLARE @intRemainder DECIMAL(7,2),@intDividend bigint,@strBranchCode VARCHAR
DECLARE @intWidth1 INT,@intWidth2 INT, @intWidth3 INT
DECLARE @CharacterSet VARCHAR
DECLARE C1 CURSOR FOR SELECT No FROM Pol 
WHERE No='0900001'
OPEN C1
    SET @CharacterSet='— :;?@[\]^ˆ_`{|}~¡¦¨¯´¸¿˜‘”<=>±×÷¢£¤¥§©¬®°µ¶·†‡•…‰€0¼½¾123456789AªÁÀÂÄÃÅÆBCÇDÐEÉÈÊËFƒGHIÍÌÎÏJKLMNÑOºÓÒÔÖÕØŒPQRSŠßTÞ™UÚÙÛÜVWXYÝŸZ'
    SET @intCounter=0
    SET @strResult2=''
    SET @strResult3=''
    SET @strResult4=''
    SET @strResult5=''
    SET @strResult6=''
    FETCH NEXT FROM C1 INTO @strNo
    WHILE @@FETCH_STATUS=0
        BEGIN   
            SET @intCounter = @intCounter + 1
            SET @intDecimalValueYear=YEAR(GETDATE())
            SET @intDecimalValueMonth=MONTH(GETDATE())
            SET @intDecimalValueDay=DAY(GETDATE())
            SET @intDecimalValueTimer1=(DATEPART(HH,CURRENT_TIMESTAMP) * 3600) + (DATEPART(MI,CURRENT_TIMESTAMP) * 60) + (DATEPART(SS,CURRENT_TIMESTAMP))
            SET @intDecimalValueTimer2=(DATEPART(MS,CURRENT_TIMESTAMP))
            SET @intDecimalValueTimer3=@intDecimalValueTimer1+(@intDecimalValueTimer2/1000)
            SET @intCounterTemp=@intCounter
            SET @strResult1='HQ'

            IF @intCounter > LEN(@CharacterSet)
                BEGIN 
                    SET @intCounter = 1 
                END
            --------------
            WHILE @intDecimalValueYear > 0
                BEGIN
                    SET @intRemainder = @intDecimalValueYear % LEN(@CharacterSet)
                    SET @intDecimalValueYear = @intDecimalValueYear / LEN(@CharacterSet)
                    SET @strResult2 = (RIGHT(LEFT(@CharacterSet, @intRemainder + 1),1)) + @strResult2
                END
            IF LEN(@strResult2)=1
                BEGIN
                    SET @strResult2 = '—'
                END
            ELSE IF LEN(@strResult2)=0
                BEGIN
                    SET @strResult2 = '——' + @strResult2
                END
            --------------
            WHILE @intDecimalValueMonth > 0
                BEGIN
                    SET @intRemainder = @intDecimalValueMonth % LEN(@CharacterSet)
                    SET @intDecimalValueMonth = @intDecimalValueMonth / LEN(@CharacterSet)
                    SET @strResult3 = (RIGHT(LEFT(@CharacterSet, @intRemainder + 1),1)) + @strResult3
                END
            IF LEN(@strResult3)=0
                BEGIN
                    SET @strResult3 = '—'
                END
            --------------
            WHILE @intDecimalValueDay > 0
                BEGIN
                    SET @intRemainder = @intDecimalValueDay % LEN(@CharacterSet)
                    SET @intDecimalValueDay = @intDecimalValueDay / LEN(@CharacterSet)
                    SET @strResult4 = (RIGHT(LEFT(@CharacterSet, @intRemainder + 1),1)) + @strResult4
                END
            IF LEN(@strResult4)=0
                BEGIN
                    SET @strResult4 = '—'
                END
            -------------- 
            WHILE @intDecimalValueTimer3 > 0
                BEGIN
                    SET @intRemainder = @intDecimalValueTimer3 % LEN(@CharacterSet)
                    SET @intDecimalValueTimer3 = @intDecimalValueTimer3 / LEN(@CharacterSet)
                    SET @strResult5 = (RIGHT(LEFT(@CharacterSet, @intRemainder + 1),1)) + @strResult5
                END
            IF LEN(@strResult5)=2
                BEGIN
                    SET @strResult5 = '—' + @strResult5
                END
            IF LEN(@strResult5)=1
                BEGIN
                    SET @strResult5 = '——' + @strResult5
                END
            IF LEN(@strResult5)=0
                BEGIN
                    SET @strResult5 = '———'
                END
            -------------
            WHILE @intCounterTemp > 0
                BEGIN
                    SET @intRemainder = @intCounterTemp % LEN(@CharacterSet)
                    SET @intCounterTemp = @intCounterTemp / LEN(@CharacterSet)
                    SET @strResult6 = (RIGHT(LEFT(@CharacterSet, @intRemainder + 1),1)) + @strResult6
                END
            IF LEN(@strResult6)=1
                BEGIN
                    SET @strResult6 = '—' + @strResult6
                END
            ELSE IF LEN(@strResult6)=0
                BEGIN
                    SET @strResult6 = '——'
                END
            -------------
            --SET @strResult=@strResult1 + @strResult2 + @strResult3 + @strResult4 + @strResult5 + @strResult6

            UPDATE POL
            SET ID=@strResult1 + @strResult2 + @strResult3 + @strResult4 + @strResult5 + @strResult6
            WHERE No=@strNo

            FETCH NEXT FROM C1 INTO @strNo
    END
CLOSE C1
DEALLOCATE C1
  • 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-06-01T10:42:37+00:00Added an answer on June 1, 2026 at 10:42 am

    I agree with Steve that you should set the VARCHAR to some length. However, I think that it is actually because @CharacterSet never changes that you’re stuck in the infinite loop.

    Every statement like this will set you through an infinite loop:

    SET @intDecimalValueYear = @intDecimalValueYear / LEN(@CharacterSet)
    SET @intDecimalValueMonth = @intDecimalValueMonth / LEN(@CharacterSet)
    SET @intDecimalValueDay = @intDecimalValueDay / LEN(@CharacterSet)
    -- etc...
    

    It’s like when you divide any number by 2 over and over again. It will never reach 0, but get close.

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

Sidebar

Related Questions

I don't consider myself a complete SQL novice, but I have been staring at
I'm a novice when it comes to SQL and PHP, and I'm trying to
I'm a novice when it comes to sql so forgive me if this seems
Could you please list some of the bad practices in SQL, that novice people
I am a NOVICE SQL ADMIN... I am trying to add a column 'ID'
I'm a relative sql notice, eager to learn, but I need some help putting
I'm trying to write a recursive function of sorts in PL/SQL. The problem is:
I am SQL novice and I am working on a PHP+MySql application. The database
I apologize for the long post, but this problem is not easily stated. I
I have a tough programming problem in SQL Server 2000 that I'm hoping I

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.