How to convert a given string into upper case string without using builtin UPPER function. Below is the code.
CREATE FUNCTION
udfUpper
(
@InputString NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE
@UpperString NVARCHAR(MAX) = ''
DECLARE @Counter INT = 1
DECLARE
@Character CHAR = ''
DECLARE
@AsciiValue TINYINT
DECLARE
@NewAsciiValue TINYINT
WHILE (@Counter <= LEN(@InputString))
BEGIN
SET @Character = SUBSTRING(@InputString,@Counter,1)
IF ASCII(@Character) BETWEEN 97 AND 122
BEGIN
SET
@NewAsciiValue = ASCII(@Character) - 32
SET @UpperString = @UpperString + CHAR(@newAsciiValue)
END
ELSE
BEGIN
SET @UpperString = @UpperString + @Character
END
SET @Counter = @Counter + 1
END
RETURN @UpperString
END
GO
SELECT dbo.udfUpper('this is a test
STRingdadas@#@#@')
No comments:
Post a Comment