Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Possibly a join???

Status
Not open for further replies.

grimmy26

Technical User
Oct 27, 2003
126
0
0
AU
I had a query which used to work fine:-

declare @@boo as varchar(100)
declare @@cry as varchar(100)

set @@boo = 'ghost'
set @@cry = 'wail'

Update table1 set column1=@@boo where column2=@@cry

The problem now is that column2 is now in a different table so this will not work. I can join these tables fine with an inner join and the select statement works fine but I cannot update. I believe this is because I cannot update a join.

If this is correct then has anybody any idea of how to do this?

MCSE NT4, 2000, 2003
 
Try something like this:
Code:
declare @@boo as varchar(100)
declare @@cry as varchar(100)

set @@boo = 'ghost'
set @@cry = 'wail'

Update table1 set column1=@@boo 
FROM table1, table2
WHERE table1.id = table2.id
AND column2=@@cry

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
Update t1
set column1=@@boo
FROM table1 t1
join table2 t2 On table1.id = table2.id
where column2=@@cry

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top