5 pts.
 SQL error. There is already an object named ‘InitCap2′ in the database.
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

Software/Hardware used:
ASKED: December 5, 2008  8:21 PM
UPDATED: December 5, 2008  10:25 PM

Answer Wiki:
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>
Last Wiki Answer Submitted:  December 5, 2008  10:25 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _