34,590
社区成员
发帖
与我相关
我的任务
分享
declare @NowMonth int,@CounterName varchar(100)
set @NowMonth=month(GETDATE())
insert into #ASB_SQLCountValueInfo(BlockedCounterID,BlockedCounterDateTime,BlockedCounterValue,ServerName)
select CounterID,CounterDateTime, CounterValue,‘cnjb01 ’ from dbo.ASBSQL_PerformanceCounterDetailM+'+@NowMonth+' T
where CounterID in (
select CounterID from [SQLMonitor].[dbo].[ASBSQL_PerformanceCounterList]
where ServerName=‘cnjb01 ’ and CounterName='Processes blocked'
)
and T.CounterValue>=20 and DATEDIFF(MINUTE,CounterDateTime,GETDATE())<=30
order by CounterDateTime desc
declare @NowMonth int
declare @CounterName varchar(20)
declare @serverName varchar(500)
declare @AlterIntervalTime int
declare @strSql varchar(500)
select @serverName='cnshjssql14.ad4.ad.alcatel.com'
set @CounterName='Processes blocked'
set @AlterIntervalTime=30
set @NowMonth=month(GETDATE())
set @strSql=' select CounterID,CounterDateTime, CounterValue,'''+@serverName+''' as serverName from dbo.ASBSQL_PerformanceCounterDetailM+'+CAST(@NowMonth as varchar)+' T
outer apply (
select top 1 CounterID from [SQLMonitor].[dbo].[ASBSQL_PerformanceCounterList] AS p
where p.ServerName='''+@serverName+''' and p.CounterName=''Processes blocked'' and p.CounterID=T.CounterID
) a Where a.CounterID is NULL
and T.CounterValue>=20 and DATEDIFF(MINUTE,CounterDateTime,GETDATE())>='+ cast(@AlterIntervalTime as varchar)+'
order by CounterDateTime desc'
exec (@strSql)
declare @NowMonth int
set @NowMonth=6
declare @AlterIntervalTime int
set @AlterIntervalTime=30
declare @Flag bit=0
declare @strSql nvarchar(1000)
set @strSql=' if exists(select 1 from ASBSQL_PerformanceCounterDetailM'+ CAST(@NowMonth as varchar)+' T where exists(
select 1 from [SQLMonitor].[dbo].[ASBSQL_PerformanceCounterList]
where CounterName=''Processes blocked'' and CounterID=T.CounterID
)
and CounterValue>=20 and DATEDIFF(MINUTE,CounterDateTime,GETDATE())<='+ cast(@AlterIntervalTime as varchar)+'
)
set @Flag=1
else
set @Flag=0'
EXEC sp_executesql @strSql, N'@Flag BIT output',@Flag OUTPUT
declare @strSql nvarchar(500)
DECLARE @Flag BIT=0
SET @strSql=' select TOP 1 @Flag=1 from ASBSQL_PerformanceCounterDetailM'+ CAST(@NowMonth as varchar)+' T where exists(
select 1 from [SQLMonitor].[dbo].[ASBSQL_PerformanceCounterList]
where CounterName=''Processes blocked'' and CounterID=T.CounterID
)
and CounterValue>=20 and DATEDIFF(MINUTE,CounterDateTime,GETDATE())>='+ cast(@AlterIntervalTime as varchar)+'
'
EXEC sp_executesql @strSql, N'@Flag BIT output',@Flag OUTPUT
BEGIN
IF @Flag=1
INSERT into tbname....
END
declare @NowMonth int
declare @CounterName varchar(20)
declare @serverName varchar(500)
declare @AlterIntervalTime int
declare @strSql varchar(500)
select @serverName='cnshjssql14.ad4.ad.alcatel.com'
set @CounterName='Processes blocked'
set @AlterIntervalTime=30
set @NowMonth=month(GETDATE())
set @strSql='SELECT CounterID,CounterDateTime, CounterValue from dbo.ASBSQL_PerformanceCounterDetailM'+ CAST(@NowMonth as varchar)+' T
where CounterID in (
select CounterID from [SQLMonitor].[dbo].[ASBSQL_PerformanceCounterList]
where ServerName='''+CAST(@serverName as varchar)+''' and CounterName='''+@CounterName+'''
)
and T.CounterValue>=20 and DATEDIFF(MINUTE,CounterDateTime,GETDATE())<='+ cast(@AlterIntervalTime as varchar)+'
order by CounterDateTime DESC'
exec (@strSql)
declare @NowMonth int
declare @CounterName varchar(20)
declare @serverName varchar(500)
declare @AlterIntervalTime int
declare @strSql varchar(500)
select @serverName='cnshjssql14.ad4.ad.alcatel.com'
set @CounterName='Processes blocked'
set @AlterIntervalTime=30
set @NowMonth=month(GETDATE())
set @strSql='SELECT CounterID,CounterDateTime, CounterValue from dbo.ASBSQL_PerformanceCounterDetailM'+ CAST(@NowMonth as varchar)+' T
where CounterID in (
select CounterID from [SQLMonitor].[dbo].[ASBSQL_PerformanceCounterList]
where ServerName='+CAST(@serverName as varchar)+' and CounterName=''Processes blocked''
)
and T.CounterValue>=20 and DATEDIFF(MINUTE,CounterDateTime,GETDATE())<='+ cast(@AlterIntervalTime as varchar)+'
order by CounterDateTime DESC'
exec (@strSql)
消息 4104,级别 16,状态 1,第 4 行
无法绑定由多个部分组成的标识符 "cnshjssql14.ad4.ad.alcatel.com"。
@中国风 咱解决 谢谢declare @NowMonth VARCHAR(2),@CounterName varchar(100)
set @NowMonth=month(GETDATE())
insert into #ASB_SQLCountValueInfo(BlockedCounterID,BlockedCounterDateTime,BlockedCounterValue,ServerName)
EXEC( 'SELECT CounterID,CounterDateTime, CounterValue,''cnjb01'' from dbo.ASBSQL_PerformanceCounterDetailM+'+@NowMonth+' T
where CounterID in (
select CounterID from [SQLMonitor].[dbo].[ASBSQL_PerformanceCounterList]
where ServerName=''cnjb01'' and CounterName=''Processes blocked''
)
and T.CounterValue>=20 and DATEDIFF(MINUTE,CounterDateTime,GETDATE())<=30
order by CounterDateTime DESC')