aruba
Programmer
- Sep 5, 2003
- 47
I am trying to convert anything over 1000000 to "A00000" and over 1100000 to "B00000" etc. The following code returns the correct string:
declare @char_parentwo varchar(9)
declare @parentwo bigint
set @parentwo = '1129356'
If @parentwo > 999999 and @parentwo < 1100000
set @char_parentwo = 'A' + substring(convert(varchar(9),@parentwo),3,5)
else
if @parentwo > 1099999 and @parentwo < 1200000
set @char_parentwo = 'B' + substring(convert(varchar(9),@parentwo),3,5)
print (@char_parentwo)
However when I try to change this to a function, it only returns the letter and not the remainder of the number. Here is the code:
create function wkctl.parentwo_convertToP3T(@parentwo bigint)
returns varchar
as
begin
declare @char_parentwo varchar(9)
If @parentwo > 999999 and @parentwo < 1100000
set @char_parentwo = 'A' + substring(convert(varchar(9),@parentwo),3,5)
else
if @parentwo > 1099999 and @parentwo < 1200000
set @char_parentwo = 'B' + substring(convert(varchar(9),@parentwo),3,5)
return (@char_parentwo)
end
Can anyone suggest what I'm doing wrong please?
declare @char_parentwo varchar(9)
declare @parentwo bigint
set @parentwo = '1129356'
If @parentwo > 999999 and @parentwo < 1100000
set @char_parentwo = 'A' + substring(convert(varchar(9),@parentwo),3,5)
else
if @parentwo > 1099999 and @parentwo < 1200000
set @char_parentwo = 'B' + substring(convert(varchar(9),@parentwo),3,5)
print (@char_parentwo)
However when I try to change this to a function, it only returns the letter and not the remainder of the number. Here is the code:
create function wkctl.parentwo_convertToP3T(@parentwo bigint)
returns varchar
as
begin
declare @char_parentwo varchar(9)
If @parentwo > 999999 and @parentwo < 1100000
set @char_parentwo = 'A' + substring(convert(varchar(9),@parentwo),3,5)
else
if @parentwo > 1099999 and @parentwo < 1200000
set @char_parentwo = 'B' + substring(convert(varchar(9),@parentwo),3,5)
return (@char_parentwo)
end
Can anyone suggest what I'm doing wrong please?