SQL error. There is already an object named ‘InitCap2′ in the database.

5 pts.
Tags:
InitCap2
SQL
SQL Server errors
SQL Server Management Studio
SQL Server Management Studio Express
I am running the following code in Microsoft SQL Server Management Studio Express, and after I run it, I get the following error, even though it is returning the record set that I am looking for. I would like to get rid of this error. Thanks. The error is: Msg 2714, Level 16, State 5, Procedure InitCap2, Line 30 There is already an object named 'InitCap2' in the database. My code is: CREATE FUNCTION InitCap2( @InputString varchar(4000) ) RETURNS VARCHAR(4000) AS BEGIN DECLARE @Index INT DECLARE @Char CHAR(1) DECLARE @PrevChar CHAR(1) DECLARE @OutputString VARCHAR(255) SET @OutputString = LOWER(@InputString) SET @Index = 1 WHILE @Index <= LEN(@InputString) BEGIN SET @Char = SUBSTRING(@InputString, @Index, 1) SET @PrevChar = CASE WHEN @Index = 1 THEN ' ' ELSE SUBSTRING(@InputString, @Index - 1, 1) END IF @PrevChar IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&', '''', '(') BEGIN IF @PrevChar != '''' OR UPPER(@Char) != 'S' SET @OutputString = STUFF(@OutputString, @Index, 1, UPPER(@Char)) END SET @Index = @Index + 1 END RETURN @OutputString END GO select mi.id,'PAS',category,classification,status,CompName, dbo.InitCap2(FirstName) AS FirstName, dbo.InitCap2(LastName) AS LastName, Salutation,OfficePh,HomePh,FaxNo,CellPh, CONVERT(nvarchar(20), mi.CreateDate, 101) AS JoinDate, CONVERT(nvarchar(20), expdate, 101) AS ExpDate, ci.email,web,'Work',address1,address2,City,State,Zip,Country,mailcode,HomePh,FaxNo,CellPh, '1','1',codeused from MEMBER_INFO mi,CONTACT_INFO ci where mi.id>57924 and mi.id=ci.id
ASKED: December 5, 2008  8:21 PM
UPDATED: December 5, 2008  10:25 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

It seems that you are trying to create the function more than once.

If you want to re-create the function, you could try something like this :

<pre>IF OBJECT_ID (‘dbo.InitCap2′, ‘FN’) IS NOT NULL
DROP FUNCTION dbo.InitCap2;
GO
CREATE FUNCTION InitCap2( @InputString varchar(4000) )


</pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following