Solved

Move Field values in same table

Posted on 2007-03-22
5
146 Views
Last Modified: 2013-12-16
I have a table with 3 fields, field1, field2 and field3. I need to write an update query that moves field2 to field1 AND if field3 is entered, move field3 to field1 (replacing value just moved from field2). How can I accomplish this by using coldfusion?
0
Comment
Question by:Errol Farro
  • 3
  • 2
5 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 125 total points
Comment Utility
?

update yourtable
 set field1 = coalesce(field3,field2)
where ...
0
 

Author Comment

by:Errol Farro
Comment Utility
Thanks man, you are indeed a genius. I never heard of the coalesce function.
0
 

Author Comment

by:Errol Farro
Comment Utility
Question: Is there a way to consider 0 as a not-null expression? It works fine when the value is Null but not when value is 0. Please advice.
0
 

Author Comment

by:Errol Farro
Comment Utility
Sorry for the Typo:

Question: Is there a way to consider 0 also as a null expression? It works fine when the value is Null but not when value is 0. Please advice.
0
 
LVL 50

Expert Comment

by:Lowfatspread
Comment Utility
update yourtable
 set field1 = coalesce(nullif(field3,0),field2)
where ...


nullif ( a,b) returns null if a and b are equal...  else a
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now