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 2005 Forums
 Transact-SQL (2005)
 UPDATE-Problem

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-03-03 : 09:55:59
i have table Table1

# Code flage Status
1 1 3 0
2 1 4 1
3 2 3 Null
4 2 4 1
5 3 3 0


i want that
status in row 1 like row 2 1
status in row 3 like row 4 1


# Code flage Status
1 1 3 1
2 1 4 1
3 2 3 1
4 2 4 1
5 3 3 0


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-03 : 09:58:42
What are the business rules for deciding which records to update?
Why is not record 5 updated?

Are you referring to next status should be duplicated in records having NULL and 0 in Status column?

See http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-03-03 : 12:26:55
sorry, i think that is understood.
i update rows that their flage=3, and it get status of flag=4.
like row 1 it join by code .

row 1 and row 2 are join,cause the have same code. so row 1 get the status of row 2.

something like that:

UPDATE TABLE1
SET t1.tatus=t2.Status
FROM TABLE1 t1
WHERE t1.Status=3
And
t1.Code IN (SELECT t2.Code FROM Table1 t2 WHERE t1.Code=t2.Code)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-03 : 12:29:51
[code]
UPDATE t1
SET t1.Status=t2.Status
FROM Table1 t1
JOIN Table1 t2
ON t2.Code=t1.Code
WHERE t1.flage=3
AND t2.flage=4
[/code]
Go to Top of Page
   

- Advertisement -