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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swap fields in a table

Status
Not open for further replies.

artmaat

Technical User
Apr 22, 2002
3
CA
I need to switch the info in two fields basically reverse the info. I have several hundred records to deal with. This needs to be done only when a third field is <null>
So its like this:
1) Switch COSTCODE and EQUIPMENT when EMPLOYEE is <NULL>
2) Then when EMPLOYEE is <NULL> change to '52001'
Can someone help me with the SQL statement to do this.
 
This sounds straight-forward.
Two separate update statements.

Update MyTable SET
CostCode = Equipment,
Equipment = CostCode
Where EMPLOYEE IS NULL

Update MyTable
Set EMPLOYEE = '52001'
Where EMPLOYEE IS NULL

Should work fine, but as always, test before using on live data.

bperry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top