我选择了完美的选择。
update ClientS set StatusID=4
where ClientID= (select P.ClientID
,LastName+' '+FirstName as Name
,Address
,max(p.PickupDate)as 'Last Pickup'
,DATEDIFF(month,max(p.PickupDate),GETDATE())as'last pickup was months ago'
from Pickup P
join Clients C on P.ClientID= C.ClientID
where WIC=0 and C.StatusID = 1 or WIC=0 and C.StatusID = 2
group by p.clientid, lastname + ' ' + firstname,address
order by 4)
我需要基于last pickup was months ago
此选择中的一个更新语句。我需要更新表中的客户StatusID
,Clients
并将其设置为 4,仅针对此选择中最后一次取货时间超过 2 个月的客户。到目前为止我有这个
create procedure pr_UpdateStatusHwoPickupMoreThanTwoM
AS
update ClientS set StatusID=4
where ClientID= (select P.ClientID
,LastName+' '+FirstName as Name
,Address
,max(p.PickupDate)as 'Last Pickup'
,DATEDIFF(month,max(p.PickupDate),GETDATE())as'last pickup was months ago'
from Pickup P
join Clients C on P.ClientID= C.ClientID
where WIC=0 and C.StatusID = 1 or WIC=0 and C.StatusID = 2
group by p.clientid, lastname + ' ' + firstname,address
order by 4)
我知道这是不对的,我需要以某种方式指定最后一次取货是在 2 个多月前,但无法弄清楚如何StatusID
只为那些取货和更改ClientID
。任何想法如何做到这一点?