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.

 
Go Back  dBforums > Database Server Software > Informix > Creating Function for Formatting Phone Number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-05, 09:52
zombie_man23 zombie_man23 is offline
Registered User
 
Join Date: Jul 2005
Posts: 24
Creating Function for Formatting Phone Number

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
Reply With Quote
  #2 (permalink)  
Old 12-08-05, 15:20
artemka artemka is offline
Registered User
 
Join Date: May 2004
Location: New York
Posts: 248
why dont you try something like this

let numchars = length(phone)

if numchars = 10 then
let scratch = "(",phone[1,3],")","-",phone[4,6],"-",phone[7,10]
end if

and the same thing for 7 numbers

Hope this hels

Cheers

Artem
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On