Below Query creates a function to display the text in sentence caps, e.g.., displays 'ANANDH KUMAR' as 'Anandh Kumar'
CREATE FUNCTION [dbo].[ProperCase](@Input AS VARCHAR(8000))
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @Reset BIT;
DECLARE @Ret VARCHAR(8000);
DECLARE @i INT;
DECLARE @c CHAR(1);
SELECT @Reset = 1, @i=1, @Ret = '';
WHILE (@i <= LEN(@Input))
SELECT @c= SUBSTRING(@Input,@i,1),
@Ret = @Ret + CASE WHEN @Reset=1 THEN UPPER(@c) ELSE LOWER(@c) END,
@Reset = CASE WHEN @c LIKE '[a-zA-Z]' THEN 0 ELSE 1 END,
@i = @i +1
RETURN @Ret
END
No comments:
Post a Comment