0

我有声明

update Clients
set StatusID= 4
from (select c.clientid
from Clients c
where CategCode = 'CH' and StatusID in (1,2,6) and DATEDIFF(YEAR,dob,GETDATE())>5)

它给我带来了错误

Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ')'.

你知道什么会导致这个错误吗?

我试图使用这个语句,但它为所有客户端设置了状态 4

update Clients
set StatusID= 4
WHERE EXISTS( 
select clientid,DOB,DATEDIFF(YEAR,dob,GETDATE())
from Clients 
where CategCode = 'CH' and StatusID in (1,2,6) and DATEDIFF(YEAR,dob,GETDATE())>5
4

1 回答 1

1

试试这个

update c
set c.StatusID= 4
from Clients c
where CategCode = 'CH' and StatusID in (1,2,6) 
and DATEDIFF(YEAR,dob,GETDATE())>5

您的第二个查询应该是

update c
set StatusID= 4
from Clients c
WHERE EXISTS( 
select 1
from Clients x
where CategCode = 'CH' and StatusID in (1,2,6)  and x.clientid = c.clientid)
于 2013-03-17T22:16:35.663 回答