ALTER PROCEDURE Sp_Num_Tracking
@UserID int
AS
BEGIN
declare @lastLogonDate datetime;
ALTER PROCEDURE Sp_num_Tracking
@UserID int
AS
BEGIN
declare @lastLogonDate datetime;
declare @CurrentLogonDate datetime;
declare @onemonthtime datetime;
declare @frmbeg int;
declare @oneweektime datetime;
select @lastLogonDate= max( crimedate) from tblcrime where UserID=@UserID
set @CurrentLogonDate=getdate()
set @onemonthtime=dateadd(mm,-1,@CurrentLogonDate)
set @oneweektime=dateadd(dd,-7,@CurrentLogonDate)
select @frmbeg= max(crimeID)-min(CrimeID) from tblcrime
SELECT count(o.crimeID)
from tblcrime o
inner join
tblContractor ts
on o.MainContractorID=ts.ContractorID
inner join
tblBusiness tb
on o.MainContractorBUID=tb.BusinessID
inner join tblservant tw on
o.servantID=tw.servantID
inner join tblUser u
on u.ContractorID=o.MainContractorID
where count(o.crimeID) between @lastLogonDate and @onemonthtime or count(o.crimeID) between @lastLogonDate and @oneweektime
END
ただし、次のようなエラーが発生します。「HAVING句または選択リストに含まれるサブクエリに含まれていない限り、集計はWHERE句に表示されず、集計される列は外部参照です」。どの部分を変更したいのか....Plzヘルプ