Learning Home

Monday, 20 March 2017

Make Apostrophe in SQL Query

declare @str varchar(50)
select @str = 'ABC'''
declare @strLen int = len(@str)
declare @rtnText varchar(50)
select @rtnText = ''
if @strLen > 0
begin
declare @i int = 0
while @i <= @strLen
begin
select @rtnText = @rtnText + substring(@str,@i,1)
if substring(@str,@i,1) = ''''
select @rtnText = @rtnText + ''''
set @i = @i + 1
end
end
print @rtnText

No comments:

Post a Comment