Given a word, write a SQL query to find and display the distinct vowels (A, E, I, O, U) present in that word.
Expected Output:
Try solving the question yourself! If you need help, click below to reveal the solution.
Given a word, write a SQL query to find and display the distinct vowels (A, E, I, O, U) present in that word.
Try solving the question yourself! If you need help, click below to reveal the solution.
DECLARE @A VARCHAR(300)='FABRICOFDATA'
DECLARE @END INT =1
DECLARE @BEGIN INT=0
DECLARE @CHECKER VARCHAR(5)
DECLARE @VOWELS VARCHAR(250)=NULL
WHILE @begin<=(SELECT LEN(@A))
BEGIN
SET @CHECKER=(SELECT SUBSTRING(@A,@Begin,@End-@Begin))
IF @CHECKER IN ('a','e','i','o','u')
BEGIN
SELECT @VOWELS= IIF(@Vowels IS NULL,'',@Vowels+',')+@checker
End
SET @BEGIN =@BEGIN+1
SET @END=@END+1
END
SELECT @A AS INPUT_STRING
SELECT STRING_AGG(VALUE,',') AS Vowels
FROM
(
SELECT DISTINCT * FROM
(
SELECT VALUE FROM string_split(@Vowels,',')
) a
)b