I am trying to write a function which will return number of vowels and consonants. Using the IF statement function will successfully compile, however when I call it in the select it shows the message :
"Conversion failed when converting the varchar value 'MAMAMIA' to data type int."`
I tried with the CASE statement, but there are too many syntax errors and i think it is not the best method of solving the problem using CASE ...
CREATE FUNCTION VOW_CONS(@ARRAY VARCHAR(20))
RETURNS INT
BEGIN
DECLARE @COUNTT INT;
DECLARE @COUNTT1 INT;
SET @COUNTT=0;
SET @COUNTT1=0;
WHILE (@ARRAY!=0)
BEGIN
IF(@ARRAY LIKE '[aeiouAEIOU]%')
SET @COUNTT=@COUNTT+1
ELSE SET @COUNTT1=@COUNTT1+1
/*
DECLARE @C INT;
SET @C=(CASE @SIR WHEN 'A' THEN @COUNTT=@COUNTT+1;
WHEN 'E' THEN @COUNTT=@COUNTT+1
WHEN 'I' THEN @COUNTT=@COUNTT+1
WHEN 'O' THEN @COUNTT=@COUNTT+1
WHEN 'U' THEN @COUNTT=@COUNTT+1
WHEN 'A' THEN @COUNTT=@COUNTT+1
WHEN ' ' THEN ' '
ELSE @COUNTT1=@COUNTT1+1
END)
*/
END
RETURN @COUNTT;
END
SELECT DBO.VOW_CONS('MAMAMIA')
Aucun commentaire:
Enregistrer un commentaire