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 2008 Forums
 Transact-SQL (2008)
 Change column value query

Author  Topic 

murd
Starting Member

24 Posts

Posted - 2012-12-03 : 15:08:00
I need to update/change values to a column w/ a specific range
from a different table.


example


table1 table 2
CID DID
1 100
2 200
3 300
4 400
5 500
6 600

I want to update CID from <=4 to the corresponding DID

Results
CID
100
200
300
400

hope I explained this right...thx

shilpash
Posting Yak Master

103 Posts

Posted - 2012-12-03 : 16:46:08
so do you want your final output look like these--

CID DID
100 100
200 200
300 300
400 400
5 500
6 600
Go to Top of Page

shilpash
Posting Yak Master

103 Posts

Posted - 2012-12-03 : 16:52:44
If so,use this---
UPDATE tablename
SET cid = did
FROM tablename
WHERE cid <= 4
Go to Top of Page

murd
Starting Member

24 Posts

Posted - 2012-12-04 : 00:07:57
yes!! thanks ill try this
Go to Top of Page
   

- Advertisement -