C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Swap the values of two columns


Posted Date: 10 Mar 2004    Resource Type: Articles    Category: Databases
Author: Satheesh SugumaranMember Level: Gold    
Rating: Points: 10



At times you may need to swap the values of two columns of the same SQL Server table. For example, suppose that you realized that the firstname column of the Employees table contains the lastast name of each employee, and vice versa.

We can take advantage of T-SQL and perform this operation much faster, This is possible by using T-SQL temporary variables and the capability to assign and use them inside an UPDATE statement. This is the T-SQL statement that performs the swap:

Here i have used Northwind database's Employees table

DECLARE @tmp VARCHAR(50)
UPDATE employees SET @tmp=firstname, firstname=lastname, lastname=@tmp




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Quickly copy records between tables with same structure
Previous Resource: Missing field in subquery doesn't raise any error
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use