1
嗨我寫了一些TSQL代碼的做法,試圖計算一個字符串中的元音字母,小寫和大寫字母,我的代碼工作了元音,但不知何故,計算所有字母爲小寫字母,這是我的代碼:TSQL計數uppcase和小寫字母
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'
請幫幫忙,謝謝
非常感謝你@ybo!只要'Latin1_General_BIN'有效,我就很開心。 – 2013-03-08 08:46:03
如果您認爲這是一個有效的答案,請標記爲這樣,謝謝! – ybo 2013-03-08 13:05:36