Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Is there a way to format a string in an SQL statement?
Sat, May 10 2014 7:41 AMPermanent Link

Aaron Taylor

Avatar

Hi all, Is there a way to format a string in SQL ?

Example: SELECT Id, Name, Phone FROM Contacts
Returns: 1, Tony, 0411234234

I would like to return: 1, Tony, (0411) 234-234
Sat, May 10 2014 7:59 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Aaron,


SELECT
  Id, Name, '(' + SUBSTRING(Phone, 1, 4) + ') ' + SUBSTRING(Phone, 5, 3) + '-' + SUBSTRING(Nome, 8, 3)
FROM
  Contacts


The other option would be to write a user defined function, but if you use Client/Server that means recompiling the server.

--
Fernando Dias
[Team Elevate]
Sat, May 10 2014 8:02 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Aaron,

Correction: It should be "Phone" instead of "Nome".

--
Fernando Dias
[Team Elevate]
Sat, May 10 2014 9:14 AMPermanent Link

Aaron Taylor

Avatar

Thank You
Image