Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how to separate a string by comma using substring every 16 digits

$
0
0

I am trying to separate a string that consists of integers by comma. For example,  @string = '22222222222222223333333333333333', I want to convert it to  @string ='2222222222222222,33333333333333'

For every 16 digits, put a comma delimited string. Here is my code, but doesn;t work correctly. Please correct me. thanks

declare @string nvarchar(max)
declare @length  int
declare @string2 nvarchar(max)
declare @i int
set @string = '22222222222222223333333333333333'
--set @length = 2
set @i = 1
while @length = len(@string)/16
begin
select @string2 = substring (@string,@i,16)+','
set    @i = @i+16
end
select @string2


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>