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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select-Update Query Help!!!

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 Proc
148965 1054 Pass 1__ Null Null Null Null Null Assy
149350 1054 Fail__ 1__ 1__ Null Null Tec 291 Test
149350 1054 Fail__ 0__ 0__ Null Null Wor 296 Test
149350 1054 Fail__ 0__ 0__ Null Null Wor 297 Test
149521 1054 Pass 1__ Null Null Null Null Null Debu
243596 1054 Pass 1__ Null Null Null Null Null sec
245580 1054 Pass 1__ Null Null Null Null Null Cyc
245894 1054 Pass 1__ Null Null Null Null Null Tx
245905 1054 Pass 1__ Null Null Null Null Null close


For 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 this

SELECT * 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
Go to Top of Page
   

- Advertisement -