SQLTeam.com | Weblogs | Forums

Trimming number by even location in a row


#1

I would like to find a way to trim a set of numbers by even location in a row. For example: 36303032363038333031. The output should be like 6002608301


#2

Cast as character then pull what you need. Cast the result back to the number format you wish.


#3

I will try that, thanks


#4

Hi djj55,

Thanks for your reply.

I'm a beginner in this.

Could you kindly provide an example.

I will try to grasp from there.

Thanking you in advance.


#5

What is the criteria for the trim?


#6
declare    
    @str    varchar(20) = '36303032363038333031',
    @p    int,
    @o    varchar(20)

select    
    @p    = len(@str),
    @o    = ''
while    @p    >= 1
begin
    select    @o = substring(@str, @p, 1) + @o
    select    @p = @p - 2
end
select    @o