---Input String 'PABITRA MICROSOFT PabiTra miCroSoft'
declare @SQLColumnName nvarchar(max)
set @SQLColumnName = 'PABITRA MICROSOFT PabiTra miCroSoft'
declare @SpaceInWord char(1) = ' '
-- Upper case first letter and all others in lower case letters
select @SQLColumnName = STUFF(LOWER(@SQLColumnName), 1, 1, UPPER(LEFT(@SQLColumnName,1)) )
-- search for space character
declare @i int = CHARINDEX(@SpaceInWord, @SQLColumnName, 1)
while @i > 0
begin
select @i = @i + 1
-- replace character after space with its upper case letter
select @SQLColumnName = STUFF(@SQLColumnName, @i, 1, UPPER( SUBSTRING(@SQLColumnName, @i, 1)) )
-- search for next space character
select @i = CHARINDEX(@SpaceInWord, @SQLColumnName, @i)
end
select @SQLColumnName
---Out Put : 'Pabitra Microsoft Pabitra Microsoft'
using cursor
----------
declare @PrinterId int,@SQLColumnName varchar(1000)
declare _cursor cursor read_only for
select PrinterId,PAddress from PrinterDetails
open _cursor
fetch next from _cursor into @PrinterId,@SQLColumnName
while @@FETCH_STATUS=0
begin
-----------------------------Body
declare @SpaceInWord char(1) = ' '
-- Upper case first letter and all others in lower case letters
select @SQLColumnName = STUFF(LOWER(@SQLColumnName), 1, 1, UPPER(LEFT(@SQLColumnName,1)) )
-- search for space character
declare @i int = CHARINDEX(@SpaceInWord, @SQLColumnName, 1)
while @i > 0
begin
select @i = @i + 1
-- replace character after space with its upper case letter
select @SQLColumnName = STUFF(@SQLColumnName, @i, 1, UPPER( SUBSTRING(@SQLColumnName, @i, 1)) )
-- search for next space character
select @i = CHARINDEX(@SpaceInWord, @SQLColumnName, @i)
end
--select @SQLColumnName
update PrinterDetails set PAddress=@SQLColumnName where PrinterId=@PrinterId
-----------------------------Body end
fetch next from _cursor into @PrinterId,@SQLColumnName
end
close _cursor
deallocate _cursor