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
 General SQL Server Forums
 New to SQL Server Programming
 Update problem

Author  Topic 

Dreamd
Starting Member

2 Posts

Posted - 2013-03-22 : 05:44:03
Hi i need to update a table but i dont know how to do it right..

table:

product_id; description; Tkey
100 ; xxx ; 100
201 ; xxy ; 201
1201 ; aaa ; 1201
1100 ; bbb ; 1100
'FFFF' ; zzz ; 'GENERIC'


id like to set column "Tkey" like

SET Tkey = Tkey WHERE product_id - 1000 EXISTS in product_id

after the update the table should look like :

product_id; description; Tkey
100 ; xxx ; 100
201 ; xxy ; 201
1201 ; aaa ; 201
1100 ; bbb ; 101
'FFFF' ; zzz ; 'GENERIC'

can someone help me please?

sorry for my bad english

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-22 : 05:47:08
[code]
UPDATE t
SET t.Tkey = t1.Tkey
FROM table t
INNER JOIN table t1
ON t1.product_id = t.product_id -1000
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Dreamd
Starting Member

2 Posts

Posted - 2013-03-22 : 06:27:28
Thank you visakh16 !
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-22 : 06:34:45
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -