CREATE FUNCTION
udfLower
(
@InputString NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE
@LowerString 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 65 AND 90
BEGIN
SET
@NewAsciiValue = ASCII(@Character) + 32
SET @LowerString = @LowerString + CHAR(@newAsciiValue)
END
ELSE
BEGIN
SET @LowerString = @LowerString + @Character
END
SET @Counter = @Counter + 1
END
RETURN @LowerString
END
GO
SELECT dbo.udfLower('this is a test
STRingdadas@#@#@')
No comments:
Post a Comment