using case in update statement

using case in update statement

i want to use case in update clause. i have used case in select stmt referring answer in this site. but the same syntax is not working for update stmt.my problem is update emp set case deptno when 10 then 20 when 20 then 30 when 30 then 40 when 40 then 10 else 0 end where deptno in(10,20,30,40); But it is not working. slightly change in the syntax working but for first condition only update emp set deptno=(case when 10 then 20 when 20 then 30 when 30 then 40 when 40 then 10 else 0)end;

View Answers

November 13, 2010 at 3:57 PM

Hello Friend,

Try this:

update emp set deptno= case
   when deptno= 10
     then deptno* 20
when deptno= 20
     then deptno* 30
when deptno= 30
     then deptno* 40
when deptno= 40
     then deptno* 10
else deptno* 0
end

Thanks


November 16, 2010 at 4:28 PM

thanks friend i got the query for case in update right.

with regards









Related Tutorials/Questions & Answers:
using case in update statement
using case in update statement  i want to use case in update clause... syntax is not working for update stmt.my problem is update emp set case deptno... working but for first condition only update emp set deptno=(case when 10 then 20
Find Capital using Switch-Case statement
Find Capital using Switch-Case statement In this Java Tutorial section, we are going to find the capital of our states using Switch-Case statement. For this, we have created two arrays i.e. array of states and array of capitals. Then we
Advertisements
CASE IN UPDATE IN MYSQL
CASE IN UPDATE IN MYSQL  I WANT THE SYNTAX FOR USING CASE IN UPDATE STMT IN MYSQL.ANY ONE PLEASE HELP.   Hi Friend, Visit hereADS_TO_REPLACE_1 Thanks
Update statement
Update statement  I create a access database my program When I click add button bata are adds to the my data base but when i click update button my database is not update I write this program using 3 differfnt notepad pages MY
Update Record using Prepared Statement
JDBC: Update Record using Prepared Statement In this section, you will learn how to update row using Prepared Statements. Update Record  ... statement. Update record is most important operation of database. You can update one
update statement in mysql
update statement in mysql  i am looking for mysql update statement example. Thanks
JDBC Update Statement Example
.style1 { text-align: center; } JDBC Update Statement Example JDBC update statement is used to update the records of a table using java application program. The Statement object returns an int value that indicates how many
The Update Statement in SQL.
The Update Statement in SQL.  The Update Statement in SQL.   Hi, here is the answer,ADS_TO_REPLACE_1 The update statement in the sql is written as follows- UPDATE table_name SET column_name = new_value WHERE column
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data into oracle database using jsp  iam a fresher newbie to softparsing i have one task to do soft parsing tl asked to do callable statement,stored
update statement in mysql
update statement in mysql  Update statement to update the existing... and use the update query to update the record. To update record, we write query ?UPDATE student SET fieldName=??? WHERE fieldName=?? . You can SET value
The UPDATE Statement
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through a specified criteria. In the given syntax of update statement the keyword SET
Update Records using Prepared Statement
Update Records using Prepared Statement   ... the process of updating the records by using the PreparedStatement.  Here arise a question, what is updating the records. In the case of relational database
The UPDATE Statement, SQL Tutorial
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through a specified criteria. In the given syntax of update statement the keyword SET
using switch case
using switch case  Define a class MENU to perform the following operation depending upon the users choice using switch case 1)print square root...){ case 1: System.out.println("Square Root of "+num
JDBC Prepared Statement Update
Statement Update is used to update the SQL statement, using where clause... JDBC Prepared Statement Update   ... in understanding JDBC Prepared Statement Update. The code include a class Jdbc Prepared
HQL Update Statement to update database table
HQL Update Statement to update database table HQL's update query statement is used to update the values of database rows. Though HQL is similar to SQL...(e.getMessage()); } } } Output of UPDATE Statement: log4j:WARN
Statement Batch Update
Statement Batch Update       In this section we are going to learn about the batch update... are added in the Statement object and update the records of database simultaneously
Case-insensitive ordering using Hibernate Criteria.
Case-insensitive ordering using Hibernate Criteria.  What is Case-insensitive ordering in Hibernate Criteria
i need to replace this if statement code with switch case code
i need to replace this if statement code with switch case code   i need to replace this code with switch case for(int i=0;i<100;i++){ if((i...){ switch(i/j){ case 3: System.out.println ("java
JDBC Batch Example With SQL Update Statement
JDBC Batch Example With SQL Update Statement: In this tutorial, we are discuss about update SQL statement with the jdbc batch. Now we will create a java...;); Now we will create Statement object by using createStatement() method
Update value of database using hibernate.
Update value of database using hibernate.  How to update value of database using hibernate?   Hibernate provides facility to update... this by setting the value and calling the update method. session.update(employee
update excel sheet using jsp::
update excel sheet using jsp::   Hi Sir,... I have a excel... given excel sheet and display it into another excel sheet using jsp" i am using 'session' to get the empid from one page to another jsp
Writing a loop statement using Netbean
Writing a loop statement using Netbean  Write a loop program using NetBeans.   Java Loops class Loops{ public static void main(String[] args){ int sum=0; for(int i=1;i<=10;i
Case-insensitive equals using Hibernate Criteria.
Case-insensitive equals using Hibernate Criteria.  How to use Case-insensitive equals with Hibernate Criteria?   The Case Insensitive ignores the case of the latter. It Selects all the records of the table related
how to update table using inner joins
how to update table using inner joins  how to update table using inner joins
Using insert update and delete in the same servlet
Using insert update and delete in the same servlet  How to write insert, update and delete coding in the same servlet
update database using two queries at a time
update database using two queries at a time  String sql="insert... can execute two queries with two different Statement object in the following way. Another thing, you have executed same query twice in your code. Statement st1
update a particular of mysql table using servlet
update a particular of mysql table using servlet  how to update a particular column for the entire table by taking requests from html form and update the particular column with out affecting other attribute values in the tuple
Case-sensitive equals using Hibernate Criteria.
Case-sensitive equals using Hibernate Criteria.  How to check for case sensitive equals in Hibernate criteria?   package net.roseindia.main; import java.util.*; import net.roseindia.table.Employee; import
JDBC Batch SQL Update Statement Example With Return Number of Effected Rows
JDBC Batch SQL Update Statement Example With Return Number of Effected Rows: In this example, we are discuss about update statement with return number... represents the update count for the respective update statement. First we
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
how do i update my database with the help of update syntax in html ? How to write 'where' statement in this?  var sqlmek="update into Student_info...'); alert('Press OK to Update your Records Successfully
PreparedStatement using batch update - Java Beginners
PreparedStatement using batch update  How to execute different preparedStatement object using batch update(Java) Pls explain with the code... + db, user, pass); pst = con.prepareStatement("update data set address
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.  String sql = "UPDATE emp_details SET empEname = ?, emailId = ?, guid =?, proximityCard =?, managerEmailId = ?, reviewerEmailId
Prepared Statement With Batch Update
Prepared Statement With Batch Update   ... Prepared Statement Batch Update Example! Added Successfully! After executing... with BatchUpdate and we are going to provide an example that performs batch update
Case-insensitive search using Hibernate Query Language(HQL).
Case-insensitive search using Hibernate Query Language(HQL).  What is Case-insensitive search using Hibernate Query Language
Insert Date using Statement - Development process
Insert Date using Statement   Hi, plz send me code for Storing system date using statement instead of preparedstatement. Thanks Prakash  Hi Friend, Try the following code: Thanks
Write a java program to display the season given the month using switch case
Write a java program to display the season given the month using switch case  Write a java program to display the season given the month using switch case
Switch case in java
block. A statement in switch is labeled with one or more case or default...Switch case in java In this section we will learn about switch case in java..., and java, switch case is used . switch  is a selection control mechanism used
Read Excel data using JSP and update MySQL databse
Read Excel data using JSP and update MySQL databse  HOw to read excel data using JSP and update MySQl database
to write an SQL query using insert statement
to write an SQL query using insert statement  I need to write an sql query for the below using InSERT command.pls help. Insert 5-star ratings by James Cameron for all movies in the database. Leave the review date as NULL
JDBC: Select Records using Prepared Statement
JDBC: Select Records using Prepared Statement In this section, you will learn how to retrieve records of table using Prepared Statement. Select Records   : Prepared Statement is precompiled SQL Statements which are stored
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database... upload excel file and update database using JSP ? Thanks in Advance
Case Java Keyword
statement in java program. In other word Case is a java keyword... programming statement case block will not have the implicit ending point. At java statement every time break statement will typically be used at the end of each case
Switch Case in Java
case label A statement in the switch block can be labeled with one or more case... of the statements associated with the next case will take place. Example of Switch Statement...It is very difficult and lengthy to write programs using
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
MySQL Case
MySQL Case       This example illustrates how to use case statement in MySQL database. MySQL Case... case statement. It performs the work as programming type.  The CASE
PHP MySQL Update
PHP MySQL Update       In SQL, Update is another statement which is used to update any record of a table. This command is useful when we need to update any existing value, which could
MySQL Case In Where Clause
MySQL Case In Where Clause       This example illustrates how to use case statement where clause... conditional construction then you can use MySQL case statement. It performs the work
Nested If Statement
if statement. Here we are providing you an example using Nested-If statement... Nested If Statement       In this section you will study about the Nested-if Statement in jsp.ADS
how to update values of a html form into an excel table using java servlets?
how to update values of a html form into an excel table using java servlets?  i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should

Ads