我正在尝试获取当天已创建或当天已修改的存储过程的列表。
我有以下可行的方法,并得到如下结果:
SELECT
SCHEMA_NAME(schema_id),
name as StoredProcedureName,
create_date,
modify_date
FROM
sys.procedures
WHERE
create_date >= '2018-09-12 00:00:00' OR
modify_date >= '2018-09-12 00:00:00'
ORDER BY
modify_date DESC
问题在于我试图忽略“ SqlQueryNotification”条目。因此,我希望它使我得到忽略上述名称的结果。
我尝试了以下
SELECT
SCHEMA_NAME(schema_id),
name as StoredProcedureName,
create_date,
modify_date
FROM
sys.procedures
WHERE
create_date >= '2018-09-12 00:00:00' OR
modify_date >= '2018-09-12 00:00:00' AND
name NOT LIKE '%SqlQueryNotificationStoredProcedures%'
ORDER BY
modify_date DESC
但是它仍然给我与图片相同的记录。它没有忽略那些记录,我在做什么错了?
答案 0 :(得分:1)
SqlQueryNotificationStoredProcedure
前面的占位符SqlQueryNotificationStoredProcedure
之后添加复数“ s” 所以查询看起来像这样:
SELECT s.[name] AS SchemaName, p.[name] AS StoredProcedureName, p.create_date, p.modify_date
FROM sys.procedures p
INNER JOIN sys.schemas s ON p.[schema_id] = s.[schema_id]
WHERE (p.create_date >= '2018-09-12 00:00:00' OR p.modify_date >= '2018-09-12 00:00:00')
AND p.[name] NOT LIKE 'SqlQueryNotificationStoredProcedure%'
ORDER BY p.modify_date DESC
答案 1 :(得分:0)
您需要将WHERE
的条件更改为以下内容:
--Want to keep only items that were created on or after 2018-09-12 and do not have a name
--like 'sqlquerynotification' OR items that were modified on or after 2018-09-12 and do
--not have a name like 'sqlquerynotification
WHERE
(create_date >='2018-09-12 00:00:00' AND
name NOT LIKE '%SqlQueryNotificationStoredProcedures%') OR
(modify_date>='2018-09-12 00:00:00' AND
name NOT LIKE '%SqlQueryNotificationStoredProcedures%')