Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem creating Function that converts num to char

Status
Not open for further replies.

aruba

Programmer
Sep 5, 2003
47
I am trying to create a function that changes the first 2 numbers to 'A' when the number reaches 1,000,000. The source is a numeric datatype so I need to convert it as well. Here is my code, which works as long as it's not a function. Any help would be greatly appreciated!

create function wkctl.parentwo_convertToP3(@parentwo bigint)
returns varchar
as
begin

declare @char_parentwo varchar

if @parentwo between 999999 and 1099999
select replace(@parentwo,substring(convert(varchar(15),@parentwo),1,2),'A')
set @char_parentwo = @parentwo
return (@char_parentwo)
end
 
instead of the select

set @parentwo = replace(@parentwo,substring(convert(varchar(15),@parentwo),1,2),'A')
 
Thank you! That solved my problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top