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 where conditions from two table

Author  Topic 

romeck
Starting Member

16 Posts

Posted - 2010-12-09 : 16:13:20
Hi , i have two tables: 1st table: WA: id, name, code, cat
2d: CA: id, code, xxx

the first one is conected with second like WA.cat=Ca.id , i want to set cat on CA.id where CA.code is in WA.name and try to do sth like that :

UPDATE [WA] as wa, [CA] as ca
SET wa.cat=ca.id
WHERE wa.nazwa like '%'+ca.code+'%'
GO

but it gives me :

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'as'.

How can i do it ?

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-12-09 : 16:19:37
[code]UPDATE wa
SET cat = ca.id
FROM [WA] as wa
JOIN [CA] as ca
On wa.nazwa like '%' + ca.code + '%'
GO
[/code]
Go to Top of Page
   

- Advertisement -