Define function to get last name
14>
15> CREATE FUNCTION fnName (@Name VarChar(100))
16> RETURNS VarChar(100)
17> AS
18> BEGIN
19> DECLARE @CommaPosition Int, @LastName varchar(100)
20> SET @CommaPosition = 6
21> SET @LastName = SUBSTRING(@Name, 1, @CommaPosition)
22> RETURN @LastName
23> END
24> GO
Msg 2714, Level 16, State 3, Server JAVA2S\SQLEXPRESS, Procedure fnName, Line 22
There is already an object named 'fnName' in the database.
1>
2> SELECT dbo.fnName('Washington, George')
3> GO
------------------------------------------------------------------------------------------
Washin
(1 rows affected)
1>
2> drop function fnName
3> GO
Related examples in the same category