473,668 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1206
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
5765
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 use of checkpoints (for simple recovery and Backup Log for full recovery). On several website people speak about full transaction log and the pace of growing can't keep up with the update. Therefore we want to create a script which flushes the...
3
13051
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 running at once will there be problems with data updates? The reason I ask is I'm thinking like this: User1 launches the app and the dataset is created from the data in the DB.
34
10823
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 VBA code that wrote the results of that away to the db, either creating new records or updating existing records, whichever was relevant. This may also include deleting records. Now I generally do this by opening a recordset on the source data...
1
1970
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, and etc. I'm trying to accomplish this in a single query, and be able to run this query and verify that players are in the right division. Is it possible to update multiple records in a table with a single query while having criteria?
1
1583
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 identify the earliest of these records, and then on this earliest record update a field value. Example: My Fields in the table are as follows. Log_ID, Cust_Ref_No, ActionDateTime, Action_Code The Log_ID is the primary key, and I need to...
5
10078
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 my limited knowledge of sql. The Raw data contains a number of columns with key columns similar to Name, Product and Partcode. The issue is that the Partcode column in the raw data can contain multiple values split by either a "," or a
33
3312
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 of 20 steps) On the admin page the steps are listed, in "order" order and the user can create new steps and assign an order and all is well. The problem may come in using a renumber function which should take the steps in their current order...
10
2228
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 an array of checkboxes, but my update loop is not working. Here is my code: /*---------This retrieves the records -------------*/ if($row_md) { do{ echo "<tr><td text align='right'>";
5
2902
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 best to do it this way, calling the update stored procedure for every update? Or should I be loading this data into a staging table, and if all goes well do the 'Real' Update. Or put this into a data adapter and update from that? The application...
2
1731
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 points. These records are imported from a txt file, and never manually entered. Currently there are no forms at all. The first problem is that the txt file continually gets updated by a CAD program. The second problem is that there is one extra...
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8570
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7391
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2781
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.