嗨,我正在编写一些 TSQL 代码实践,试图计算字符串中的元音、小写和大写字母,我的代码适用于元音,但不知何故它将所有字母都计为小写字母,这是我的代码:
DECLARE @name VARCHAR(200) ='Abc Efg Hij'
DECLARE @i int = 1
DECLARE @numVowels int = 0
DECLARE @numLower int = 0
DECLARE @numUpper int = 0
WHILE @i <= LEN(@name)
BEGIN
IF PATINDEX('%' + LOWER(SUBSTRING(@name, @i, 1)) + '%', 'aeiou') > 0
BEGIN
SET @numVowels += 1
END
IF SUBSTRING(@name, @i, 1) BETWEEN 'a' AND 'z'
BEGIN
SET @numLower += 1
END
ELSE IF SUBSTRING(@name, @i, 1) BETWEEN 'A' AND 'Z'
BEGIN
SET @numUpper += 1
END
PRINT SUBSTRING(@name, @i, 1)
SET @i +=1
END
PRINT 'There are ' + CAST((@numVowels) AS VARCHAR(200)) + ' vowels'
PRINT 'There are ' + CAST((@numLower) AS VARCHAR(200)) + ' lower-case letters'
PRINT 'There are ' + CAST((@numUpper) AS VARCHAR(200)) + ' upper-case letters'
请帮忙,谢谢