Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Prometeo
Starting Member
3 Posts |
Posted - 2003-08-20 : 23:03:21
|
| Hello All,I'm looking for a way to select only one row of two semiidentical rows of data and also update the table it is selected at the same time?T_-Key File_ Reas Qty Rej Tec Wor Fault FltID Proc148965 1054 Pass 1__ Null Null Null Null Null Assy149350 1054 Fail__ 1__ 1__ Null Null Tec 291 Test149350 1054 Fail__ 0__ 0__ Null Null Wor 296 Test149350 1054 Fail__ 0__ 0__ Null Null Wor 297 Test149521 1054 Pass 1__ Null Null Null Null Null Debu243596 1054 Pass 1__ Null Null Null Null Null sec245580 1054 Pass 1__ Null Null Null Null Null Cyc245894 1054 Pass 1__ Null Null Null Null Null Tx245905 1054 Pass 1__ Null Null Null Null Null closeFor instance, let's say I have MyTable as (Above) Please ignore the underscores. ( Sample for one File)Now let's say I want to do thisSELECT * From MyTable where Fault not NULL and Column (Reas) like Fail and UPDATE MyTable Set Tec = 1 WHERE Fault = Tec and then set Wor = 1 when Fault = Wor But I want the update to occur for each distinct filename, Proc when I select it, in this case I have 2 rows with Work (I only one to Update one of those two rows) to set the column wor =1.It does not matter which update but it has to be only one. I can have multiple Fault (Tec or Wor) by Process; but I only one to assign a 1 to Wor and 1 to Tec per proc. Thanks in advance. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-08-21 : 12:57:17
|
| You could use SET ROWCOUNT 1 to only update one record. You could also use an aggregate function to update one record. An example of this would be using MAX or MIN. If this doesn't help you, then please provide DDL (CREATE TABLE statement for your table) and also INSERT INTO statements for sample data.Tara |
 |
|
|
|
|
|