If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
I want to create a function to format a phone number. This is what I have but it says I have a syntax error. Anyone have any suggestions???
Thanks in advance!
CREATE FUNCTION FormatPhone (@phone CHAR(10))
RETURNS NVARCHAR(13)
AS
BEGIN
DECLARE
@number CHAR(14)
SELECT
if @number = 7 then
set @number = RIGHT(LEFT(@phone,3) + '-' + RIGHT(@phone,4)) RETURN @number END
elseif @number = 10 then
set @number = ('(' + LEFT(@phone,3) + ') ' + RIGHT(LEFT(@phone,6),3) + '-' + RIGHT(@phone,4)) RETURN @number END
end if