473,473 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to write a single update sql statement to update different setof attributes of a table

How to write a single update sql statement to update different set of
attributes of a table. In other words what will be the value of
indicator variables to ignore updates of some attributes in a update
statement.

e.g. EXEC SQL UPDATE
vA:iA
vB:iB
vC:iC
in TABLE 1 where vD = ...
What should be the indicator values in the above statement if i want to
update only vA and vB but not vC in the database table.

Thanks
galbodada

Nov 12 '05 #1
2 8804
ajay wrote:
How to write a single update sql statement to update different set of
attributes of a table. In other words what will be the value of
indicator variables to ignore updates of some attributes in a update
statement.

e.g. EXEC SQL UPDATE
vA:iA
vB:iB
vC:iC
in TABLE 1 where vD = ...
What should be the indicator values in the above statement if i want to
update only vA and vB but not vC in the database table.

Thanks
galbodada

You can use CASE expression for few columns or UNION ALL for many.
UPDATE T
SET (c1, c2, ... cn)
= (SELECT <expr1>, ... <expri>, ci+1, ..., cn
FROM TABLE(VALUES(1) AS A
WHERE <prd>
UNION ALL
SELECT c1, ..., ci, <expri+1>, ..., <exprn>
FROM TABLE(VALUES 1) AS B
WHERE NOT <prd>)
WHERE ...

Not sure whether TABLE(VALUES ..) is ANSI SQL. You can use whatever
your DBMS supplies to generate a single row table (SYSIBM.SYSDUMMY1,
DUAL, VALUES(1))

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

"ajay" <aj**@speedfactory.net> wrote in message
news:40**************@speedfactory.net...
How to write a single update sql statement to update different set of
attributes of a table. In other words what will be the value of
indicator variables to ignore updates of some attributes in a update
statement.

e.g. EXEC SQL UPDATE
vA:iA
vB:iB
vC:iC
in TABLE 1 where vD = ...
What should be the indicator values in the above statement if i want to
update only vA and vB but not vC in the database table.

Thanks
galbodada


You can do this with CASE statements.

The general form for this type of update:

EXEC SQL UPDATE <tablename>
SET <colA> CASE WHEN <indA> = 1 THEN <valA> ELSE <colA> END,
<colB> CASE WHEN <indB> = 1 THEN <valB> ELSE <colB> END,
....
<colQ> CASE WHEN <indQ> = 1 THEN <valQ> ELSE <colQ> END
WHERE <colX> = <valX> AND <colY> = <colY>;

And a specific example for a table containing customer information:

EXEC SQL UPDATE customer
SET c_first CASE WHEN :c_first_indicator = 1 THEN :c_first_value ELSE
c_first END,
c_last CASE WHEN :c_last_indicator = 1 THEN :c_last_value ELSE c_last END,
c_middle CASE WHEN :c_middle_indicator = 1 THEN :c_middle_value ELSE
c_middle END
WHERE c_id = :c_id;

If the c_first_indicator host variable is set to 1, then the c_first column
will be updated to the value of the c_first_value host variable, otherwise
the column is updated with the the current value. Similarly for other
columns.

--
Matt Emmerton
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ajay | last post by:
How to write a single update sql statement to update different set of attributes of a table. In other words what will be the value of indicator variables to ignore updates of some attributes in a...
3
by: gwaddell | last post by:
I have an Access XP ADE application connected to a SQL Server 7.0 SP4 database. I have created a timestamp column in the main table. Unfortunately, I am now getting persistent write conflict...
4
by: Thomas R. Hummel | last post by:
Hello, I am writing a stored procedure that will take data from several different tables and will combine the data into a single table for our data warehouse. It is mostly pretty straightforward...
19
by: Steve Jorgensen | last post by:
I've run across this issue several times of late, and I've never come up with a satisfactory answer to the best way to handle this schema issue. You have a large section of schema in which a...
0
by: Suler Abou | last post by:
Hi, I'm having a problem with an SQL statement, I have a statement that goes like this: "INSERT INTO table VALUES('TransID','CID',etc...);" it basically adds new data to a table. When the...
4
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
3
by: TD | last post by:
I have an unbound form that adds and updates records to one table. I use an INSERT sql statment to add a new record and a UPDATE statement to update a record. I created a function named C2F to...
22
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4....
9
by: rhaazy | last post by:
Using MS SQL 2000 I have a stored procedure that processes an XML file generated from an Audit program. The XML looks somewhat like this: <ComputerScan> <scanheader>...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.