Link to home
Start Free TrialLog in
Avatar of gogetsome
gogetsomeFlag for United States of America

asked on

update with concat

Hello, I have a phone column with numbers such as 9999999999. I'm trying to update the data to reflect
(999) 999-9999 ext. and allow up to a four character extension in the future. The datatype of the column is varchar (25).

I'm trying to use the code below but get this error:
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '('.

Here is my SQL:
update Technician
set [phone] = concat "(" + left(3) + ")" + " " + right((left,6),3) + "-" + right((left, 10),4)" + " " + "Ext." " + " " + right((left, 12),4)
where phone is not null
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Here is my SQL:
update Technician
set [phone] = "(" + left(3) + ")" + " " + right((left,6),3) + "-" + right((left, 10),4)" + " " + "Ext." " + " " + right((left, 12),4)
where phone is not null
Avatar of gogetsome

ASKER

Thanks AngelIII, that was fast!
I'm getting this error: The left function requires 2 arguments.
you should use
left(yourfield, 3)

Like this
update Technician
set [phone] = "(" + left(yourfield, 3) + ")" + " " + right(left(yourfield,6),3) + "-" + right(left(yourfield, 10),4)" + " " + "Ext." " + " " + right(left(yourfield, 12),4)
where phone is not null
I didn't check it but I guess you have a few " more than the ones needed

Please try this

update Technician
set [phone] = "(" + left(yourfield, 3) + ")" + " " + right(left(yourfield,6),3) + "-" + right(left(yourfield, 10),4) + " " + "Ext. " + " " + right(left(yourfield, 12),4)
where phone is not null
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Btw, use single quotes (') not double (") for delimiting literals; " depends on specific settings to work correctly, while ' does not.
Thanks Scott! That updated the column correctly. The other posts kept giving errors.
I will modify by table by adding an extension column and I can use a regular expression validator on the client side on the insert in the future. Thanks for the advice.