Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 replace command

Author  Topic 

cbeganesh
Posting Yak Master

105 Posts

Posted - 2004-12-06 : 15:00:42
I created a function to remove some abbervistion from a name field. when i run the function, it is not replaceing the abbreviation with spaces. If the passed name have any abbrveiation like INC or CO or or CORP, I want them to be removed from the name and return
here is the code

create function ufnRemoveAbbr(@Name varchar(500))
returns varchar(500)
as
begin

Declare @Result varchar(500)

set @result = replace(@name,'INC','')
set @result = replace(@name,'CO','')
set @result = replace(@name,'CORP','')

return @Result

end

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-12-06 : 15:26:01
show some sample data...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Hippi
Yak Posting Veteran

63 Posts

Posted - 2004-12-06 : 15:31:42
quote:
Originally posted by cbeganesh

I created a function to remove some abbervistion from a name field. when i run the function, it is not replaceing the abbreviation with spaces. If the passed name have any abbrveiation like INC or CO or or CORP, I want them to be removed from the name and return
here is the code

create function ufnRemoveAbbr(@Name varchar(500))
returns varchar(500)
as
begin

Declare @Result varchar(500)

set @result = replace(@name,'INC','')
set @result = replace(@name,'CO','')
set @result = replace(@name,'CORP','')

return @Result

end





How about

create function RemoveAbbr(@Name varchar(500))
returns varchar(500)
as
begin

Declare @Result varchar(500)

set @result = replace(@name,'INC','')
set @result = replace(@result,'CORP','')
set @result = replace(@result,'CO','')

return @Result

end
HTH
Go to Top of Page

cbeganesh
Posting Yak Master

105 Posts

Posted - 2004-12-06 : 15:39:10
It worked, I dont see any change to my code, is that ufn made the diffrence
Go to Top of Page

cbeganesh
Posting Yak Master

105 Posts

Posted - 2004-12-06 : 15:40:39
yes I see the mistake, Thanks
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-12-06 : 15:52:51
[code]
create function ufnRemoveAbbr(@Name varchar(500))
returns varchar(500)
as
begin
return REPLACE(REPLACE(REPLACE(@Name,'INC',''),'CORP',''),'CO','')
end
GO

SELECT dbo.ufnRemoveAbbr('x002548 CORP INC CO')
GO

DROP FUNCTION ufnRemoveAbbr
GO

[/code]


Brett

8-)
Go to Top of Page
   

- Advertisement -