Advertisement
dragonbs

Define Function

Oct 5th, 2023
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.74 KB | None | 0 0
  1. CREATE OR ALTER FUNCTION ufn_IsWordComprised(@setOfLetters VARCHAR(20), @word VARCHAR(20))
  2. RETURNS BIT
  3. AS
  4. BEGIN
  5.     DECLARE @i INT = 1;
  6.     DECLARE @Checker BIT = 0;
  7.  
  8.     WHILE @i <= LEN(@word)
  9.     BEGIN
  10.         DECLARE @SetLetter CHAR(1) = SUBSTRING(@word, @i, 1);
  11.  
  12.         DECLARE @j INT = 1;
  13.  
  14.         WHILE @j <= LEN(@setOfLetters)
  15.         BEGIN
  16.             DECLARE @WordLetter CHAR(1) = SUBSTRING(@setOfLetters, @j, 1);
  17.  
  18.             IF @SetLetter = @WordLetter
  19.             BEGIN
  20.                 SET @Checker = 1;
  21.                 BREAK;
  22.             END
  23.             SET @j += 1;
  24.             SET @Checker = 0;
  25.         END
  26.  
  27.         IF(@Checker = 0)
  28.             RETURN 0;
  29.         SET @i +=1;
  30.     END
  31.  
  32.     RETURN 1;
  33. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement