473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Updating a field for multiple records

Dear all,

I need to update one field in a table for a given record and visit number.

Example below is how the table looks -

SID VISIT DLCO
101 0 12
101 1 16
102 0 18
102 2 10
103 1 12
103 2 14

Here is how I would like it to look. The changes are the starred items.

SID VISIT DLCO
101 0 14*
101 1 16
102 0 18
102 2 16*
103 1 12*
103 2 14

I know it is an UPDATE statement, but I am not sure how to use it when I
need to update more than one record.

Thanks for the help in advance.

Jeff
Jul 23 '05 #1
3 1190
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications. Here is my guess:

CREATE TABLE Foobar
(sid INTEGER NOT NULL,
visit_nbr INTEGER NOT NULL,
dlco INTEGER NOT NULL,
PRIMARY KEY (sid,visit_nbr ));
update one field in a table for a given record and visit number.<<


Rows are not records and columns are not fields!

What is your rule for picking the subset of rows you marked? You can
do with stored procedure liek this.

UPDATE Foobar
SET dlco = @new_vlaue
WHERE sid = @my_sid
AND visit_nbr = @my_visit_nbr;

Jul 23 '05 #2
On Mon, 21 Mar 2005 17:18:49 -0700, Jeff Magouirk wrote:
I need to update one field in a table for a given record and visit number.

Example below is how the table looks -

SID VISIT DLCO
101 0 12
101 1 16
102 0 18
102 2 10
103 1 12
103 2 14

Here is how I would like it to look. The changes are the starred items.

SID VISIT DLCO
101 0 14*
101 1 16
102 0 18
102 2 16*
103 1 12*
103 2 14

I know it is an UPDATE statement, but I am not sure how to use it when I
need to update more than one record.


Hi Jeff,

You forgot to explain the logic: why are these three rows updated, but
none of the others? Why are the new values 14, 16, and 12?

The following UPDATE statement will make the required change on the
sample data you posted. If it as anything like what you want, I can't
tell.

UPDATE MyTable
SET DLCO = 216 - 2 * (SID - VISIT)
WHERE SID + VISIT + DLCO < 117

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3
I think you are looking for something like

update tbl1 set dlco = case sid when 101 then 14 else when 102 then 16
else when 103 then 12 else dlco end where sid in(101,102,103)

i am a little rusty with the case syntax so it may not compile :-) ....
but i think this is what you meant.

Jul 23 '05 #4

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

Similar topics

6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
3
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
1
by: davidevan | last post by:
What I'm trying to do is set a players division according to their age. So if age is 8, update division to junior, if age is 9, update division to medium, if age is 10, update division to pee wee,...
1
by: colinw | last post by:
I need to query a table of data that has multiple datetime entries in it relating to individual customer records. So one customer could have 1 entry, or it could have 10 entries. I need to be able to...
5
by: mctime | last post by:
Hello, I am attempting to split a raw data table into a new table that has split out a specific field in the raw data and created a new record for each split but I have come to an impasse due to...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
5
by: Bill Schanks | last post by:
I have a winform app (VB 2005) that allows users to export data to excel, make updates to the excel file and import the data from that Excel file and update the database. My question is: Is it...
2
tdw
by: tdw | last post by:
Hi all, I have several ideas on how to do this, but am having difficulty putting the ideas together and figuring out the most efficient way to do this. I have a database of survey coordinate...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.