Advertisement
JL-ConcepT

SQL Loop demo and column insert a-z

Dec 1st, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.85 KB | None | 0 0
  1. BEGIN
  2.  
  3. DBCC CHECKIDENT (Numbers, RESEED, 0)
  4.  
  5. DECLARE @Starter INT, @Ender INT, @CHARACTER CHAR(1), @Counter INT
  6. SET @Starter = 0
  7. SET @Ender = 1100
  8. SET @Counter = 0
  9.     --Loop from 0 to 1100
  10.     WHILE (@Starter < @Ender)
  11.         BEGIN
  12.         --Increase the Starter and the Counter with one for each iteration
  13.         SET @Starter = @Starter + 1
  14.         SET @Counter = @Counter +1
  15.  
  16.         --Here, we set the char value with the @Counter value
  17.         SET @CHARACTER = CHAR(96+@Counter)
  18.  
  19.         --We finaly insert into the ColTwo column
  20.         INSERT INTO Numbers (ColTwo) VALUES (@CHARACTER)
  21.             --Once we reach 'z', reset the Counter
  22.             IF @Counter = 26
  23.                 BEGIN
  24.                     SET @Counter = 0
  25.                 END
  26.     END
  27. END
  28.  
  29. --A Simple store proc. to count all soft vowels
  30.  
  31. CREATE PROC sp_ShowAllSoftVowels
  32. AS
  33. BEGIN
  34. SELECT COUNT(ColTwo) AS [Soft Vowels] FROM NUMBERS WHERE ColTwo IN ('a', 'e', 'o', 'u')
  35. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement