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
 can anyone help??

Author  Topic 

pipoD
Starting Member

3 Posts

Posted - 2009-08-03 : 23:17:10
Hi everyone, can someone help me with this? i am totally new to SQL.

below is my code and i wanted to do something like changing the value for x and y. do i have to cahnge the value manually or is there another way to change it?
i have my field name x and y in table 1,2,3 and 4 and if i want to change the value y to 3 where the x value is 4, i will excecute the code below

UPDATE table1 SET x= 4 WHERE (y= 3)
UPDATE table2 SET x= 4 WHERE (y= 3)
UPDATE table3 SET x= 4 WHERE (y= 3)
UPDATE table4 SET x= 4 WHERE (y= 3)

is there another way where i can just change the vaalue at one place and i execute the code for it to change the rest of the value in the table? something like

a = 4
b = 3

UPDATE table1 SET x= a WHERE (y= b)
UPDATE table2 SET x= a WHERE (y= b)
UPDATE table3 SET x= a WHERE (y= b)
UPDATE table4 SET x= a WHERE (y= b)

but this code is not executable though =( can anyone help??
tons of thanks in advance =)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-08-04 : 00:34:23
declare a and b as a variable @a, @b


declare @a int, @b int
select @a = 4,
@b = 3

UPDATE table1 SET x= @a WHERE (y= @b)
UPDATE table2 SET x= @a WHERE (y= @b)
UPDATE table3 SET x= @a WHERE (y= @b)
UPDATE table4 SET x= @a WHERE (y= @b)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-08-04 : 03:14:24
if you're looking for single update, consider creating single view out of 4 tables and updating it
Go to Top of Page
   

- Advertisement -