Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I combine two fields into one

Status
Not open for further replies.

stocktondesigns

Technical User
Aug 31, 2003
16
US
I currently have Area Code as a seperate field, seperate from the rest of the Phone Number.

Since most places where I want to use the data (exporting to our CRM application etc) I'd like to abandon the seperate area code field go with a plain old Phone number field which includes the area code at beginning. I'd like to create an update query that takes my Area codes and combines them at the begining of phone number field. I am not sure how to do this in SQL. Would appreciate any tips.
 
Like this.
Code:
select area_code + '-' + phone_number
from table
This will string the area_code and phone_number fields together with a "-" between them.

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
You may want to consider leaving it and just create a computed column in reports or the export query. I'll show you both.
Your update:
Code:
[Blue]UPDATE[/Blue] YourTable
   [Blue]SET[/Blue] Phone[Gray]=[/Gray]AreaCode[Gray]+[/Gray]Phone
   [Blue]WHERE[/Blue] Phone[Gray]=[/Gray][red]'SomeTestValue'[/red]  [green]--Remove this line later
[/green]                                [green]--See comment below.[/green]
A computed column:
Code:
[Blue]SELECT[/Blue] WhatEverFields[Gray],[/Gray] AreaCode[Gray]+[/Gray]Phone [Blue]AS[/Blue] FullPhone
   [Blue]FROM[/Blue] YourTable
Now before you do the update, try it on only one row, examine the results and change it back. Finally, you can let it rip.
-Karl


[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top