Ich kann nicht für das Leben von mir herauszufinden, wo ich falsch mit den Einfügeanweisungen, die ich als Teil dieser gespeicherten Prozedur erstellt habe. Wenn ich sie außerhalb der Prozedur mit der deklarierten Variablen führe, fügen sie Zeilen ohne Problem ein. Ich gehe davon aus, dass es sich um ein einfaches Syntaxproblem handelt, das ich vernachlässige.Insert-Anweisung als Teil der gespeicherten proc nicht Zeilen einfügen
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
Sie sollten wahrscheinlich einen Blick darauf werfen. http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/ –
@SeanLange Ich bin mir bewusst, aber ich bin ein Entwickler, der nicht versucht, das Boot zu rocken, weiß ich mehr erfahrene Programmierer im Team haben das Problem mit dem Lead-Dev bereits. –
Ugh ich beneide diese Situation nicht. Ich habe gesehen, dass der Lead-De- vice sich darauf versteift hat, gegen jeden Ratschlag überall herumzuspritzen. Es endet fast immer in einem massiven Projekt, um alles durchzugehen und loszuwerden. Aber das ist eine Diskussion für einen anderen Tag. –