Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 31st, 2007, 10:17 AM
Registered User
 
Join Date: Jul 2007
Location: mumbai, maharashtra, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to swap the table column value

hi,i have to swap the column value of table using single sql query,anyone of u know abt how to do this then pls reply to this msg.
for ex- i have a table Name which has two column-firstname and last name.i want to swap firstname with lastname.how to do this?
thanks in advance


Reply With Quote
  #2 (permalink)  
Old July 31st, 2007, 10:23 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. do you mean to do it in one query?? do you want to add new rows or update the same row??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #3 (permalink)  
Old July 31st, 2007, 06:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Homework problem?

Assuming you want to simply switch the values of the two columns in each row, this will do it:

UPDATE Yourtable
SET FirstName = LastName,
      LastName = FirstName

(Some not familiar with the set based nature of SQL may wonder how this works; i.e. without an intermediate variable... ;))



Jeff Mason
je.mason@comcast.net
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swap Images Mike707 Dreamweaver (all versions) 3 December 18th, 2006 01:05 PM
swap image onclick The Beginner Javascript How-To 2 November 8th, 2006 08:42 AM
Problem to Swap two number in C# furqanms C# 1 June 5th, 2006 05:12 PM
How to Swap two integers without temp variable ramk_1978 C# 2 February 28th, 2006 08:03 PM
how to make column of table 1 = to column of table gilgalbiblewheel Classic ASP Databases 4 October 11th, 2004 11:57 PM



All times are GMT -4. The time now is 06:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.