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