我不能爲我的生活找出我出錯的地方,我已經創建了插入語句作爲此存儲過程的一部分。如果我在聲明變量的過程之外運行它們,它們插入的行沒有問題。我假設它是一個我忽略的簡單語法問題。插入語句作爲存儲過程的一部分,不插入行
BEGIN
SET NOCOUNT ON;
declare @SixMinCount int = 0
, @SixtyMinCount int = 0
, @Change float = 0.0
, @PercentThreshold float = 0.07
, @CountThreshold int = 900
, @QualityLogNote varchar(500) = ''
select @SixMinCount = COUNT(0)
from dbo.Company c
join dbo.CollectionSite cs with (nolock)
on cs.CompanyId = c.CompanyId
join dbo.SystemCode sc with (nolock)
on sc.SystemCodeId = c.CompanyStateCd
AND sc.SystemCodeTypeId = 12
where c.ActiveInd = 'Y' --only active sites
AND c.ApprovedInd = 'Y' --only approved sites
AND cs.OwningNetworkId = 32971 --fieldprint network
AND cs.TestSiteInd = 'N' --non test sites
AND (select MAX(convert(varchar,lsWorkstationRequest.CreatedDt,120)) from dbo.lsWorkstationRequest where lsWorkstationId = c.CompanyId) > DATEADD(MI, -6, GETDATE()) --has not connected within the last five minutes
AND c.CompanyNm not like 'fp%' --corporate stations and some demo/test stations that aren't marked as such
select @SixtyMinCount = COUNT(0)
from dbo.Company c
join dbo.CollectionSite cs with (nolock)
on cs.CompanyId = c.CompanyId
join dbo.SystemCode sc with (nolock)
on sc.SystemCodeId = c.CompanyStateCd
AND sc.SystemCodeTypeId = 12
where c.ActiveInd = 'Y' --only active sites
AND c.ApprovedInd = 'Y' --only approved sites
AND cs.OwningNetworkId = 32971 --fieldprint network
AND cs.TestSiteInd = 'N' --non test sites
AND (select MAX(convert(varchar,lsWorkstationRequest.CreatedDt,120)) from dbo.lsWorkstationRequest where lsWorkstationId = c.CompanyId) > DATEADD(MI, -60, GETDATE()) --has not connected within the last five minutes
AND c.CompanyNm not like 'fp%' --coporate stations and some demo/test stations that aren't marked as such
IF (@SixMinCount < @CountThreshold)
begin
return 1; -- 1 denotes 'something is wrong'
set @QualityLogNote = ('The total number of Sites connected is below the minimum threshold.'
+ Char(10) + char(13) + 'Sites Connected Number Threshold = '+ convert(varchar, @CountThreshold) + Char(10)+ Char(13) +
'Sites Currently Connected = ' + Convert(varchar, @SixMinCount))
insert into QualityLog (NonconformityCd, OccuranceDt, ActiveInd, DeliveredInd, CorrectedInd, Notes)
values ('FP-IT Site Alert', GetDate(), 'Y', 'N', 'N', @QualityLogNote)
end
--ELSE
begin
select @Change = (@[email protected])/1337.0--.0 to force sql server to use float
if (@Change > @PercentThreshold)
begin
return 1;
set @QualityLogNote = ('There has rapid change in the number of sites connecting in the past 6 minutes'
+ Char(10) + char(13) + 'Threshold for % change in number of sites connected = '+ convert(varchar, Cast(Cast((@PercentThreshold)*100 as decimal(18,2)) as varchar(5)) + '%') + Char(10)+ Char(13) +
'Percent change between cycles = ' + Convert(varchar, Cast(Cast((@Change)*100 as decimal(18,2)) as varchar(5)) + '%'))
insert into QualityLog (NonconformityCd, OccuranceDt, ActiveInd, DeliveredInd, CorrectedInd, Notes)
values ('FP-IT Site Alert', GetDate(), 'Y', 'N', 'N', @QualityLogNote)
end
else
begin
return 0; -- 0 denotes 'all is well'
end
end
END
你應該仔細看看這個。 http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/ –
@SeanLange我知道,但我是一個開發人員沒有試圖搖搖欲墜的人,我知道更多有經驗的團隊成員已經提出已經是主要開發者的問題了。 –
呃我不羨慕那種情況。我已經看到主要開發者堅決反對在所有建議中反對的立場。它幾乎總是以一個龐大的項目結束,經歷一切並擺脫它。但這是另一天的討論。 –