SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Dreamd
Starting Member

2 Posts

Posted - 03/22/2013 :  05:44:03  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 03/22/2013 :  05:47:08  Show Profile  Reply with Quote

UPDATE t
SET t.Tkey = t1.Tkey
FROM table t
INNER JOIN table t1
ON t1.product_id = t.product_id -1000


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

Go to Top of Page

Dreamd
Starting Member

2 Posts

Posted - 03/22/2013 :  06:27:28  Show Profile  Reply with Quote
Thank you visakh16 !
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 03/22/2013 :  06:34:45  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000