Hi ,
yesterday my friend asked me how to display the string letter by letter in sql server
we have string function substring used here
below is the script for this
use tempdb
go
if object_id(‘tempdb..#temp’) is not null
begin
drop table #temp
end
go
– declaring the variable to store the string
declare @test varchar(100)
set @test=’chaitanya’ — assigning the value to the variable
declare @count int
select @count=len(@test)
declare @i int
set @i=1
create table #temp
(
column1 varchar(100)
)
declare @result varchar(100)
declare @j int
set @j=0
while(@i <=@count)
begin
select @result =substring(@test,@j,@i+1)
insert #temp(column1)
select @result
set @i=@i+1
end
select * from #temp
Result:
c
ch
cha
chai
chait
chaita
chaitan
chaitany
chaitanya
Please let me know if you have any concerns or any suggestions
Please check and let us know if you have any concerns or any suggestion on this
Thanks for viewing this.
Regards,
Chaitanya
Visit site: http://www.sqlblogging.com
Send an Email: sqlblogging