http://working-log.blogspot.com/2013/06/cara-membuat-looping-pada-sql-server.html
http://www.blackwasp.co.uk/SQLWhile.aspx
nested
https://www.tutorialgateway.org/nested-sql-while-loop/
---------------------------
--Nested SQL While Loop Example
DECLARE @Val1 INT,
@Val2 INT
SET @Val1 = 1
WHILE @Val1 <= 5
BEGIN
SET @Val2 = 1
WHILE @Val2 <= 3
BEGIN
PRINT CONVERT(VARCHAR, @Val1)+ ' * '
+ CONVERT(VARCHAR, @Val2)
SET @Val2 = @Val2 + 1
END
SET @Val1 = @Val1 + 1
END
-----------------------
---------------------------------------------------------
DECLARE @Val1 INT,
@Val2 INT
--SELECT b.[NPWP]
--FROM [TES].[dbo].[MON_UPDATE_KEPUTUSAN_PLENO] a
--right join [dbo].[MON_KANDIDAT_PLENO] b
--on a.npwp = b.npwp
--group by b.npwp
--where b.usulan_ in (400,600)
SET @Val1 = 1
WHILE @Val1 <= 4
BEGIN
SET @Val2 = 1
WHILE @Val2 <= 3
BEGIN
PRINT ''
SELECT case @Val2
WHEN 1 THEN 'A'
WHEN 2 THEN 'B'
ELSE 'C'
END
+CONVERT(VARCHAR, @Val1)
SET @Val2 = @Val2 + 1
END
SET @Val1 = @Val1 + 1
END
---------------------------
Langganan:
Posting Komentar (Atom)
0 Response to "perulangan sql server , while, nested while (loop)"
Posting Komentar