This function will replace multiple spaces into single space.
Recursive Solution:
CREATE FUNCTION [dbo].[ufn_TrimSpaces]
(
@strDetails varchar(100)
)
RETURNS varchar(100)
AS
BEGIN
WHILE CHARINDEX(' ',@strDetails) > 0
BEGIN
SET @strDetails = REPLACE(@strDetails, ' ',' ')
END
RETURN LTRIM(RTRIM(@strDetails))
END
to test:
declare @test varchar(100)
set @test = ' This is sample text '
select dbo.ufn_TrimSpaces(@test)
Thursday, June 21, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment