私はSQLの初心者です。私の問題は、以下のコードで無限ループが見つからないことです。クエリは実行され続けますが、その理由はわかりません。誰かが私のコードの間違いを指摘できますか?
追加の詳細: 3500 エントリに対してこのクエリを実行します。クエリの実行がおそらく遅すぎることはわかっています。そのため、より高速な方法についても聞きたいと思います。
前もって感謝します。
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