sqlserver

1.按最后修改时间降序排序

SELECT
    p.name AS ProcedureName,
    p.create_date AS CreationDate,
    p.modify_date AS LastModifiedDate,
    m.definition AS ProcedureDefinition
FROM
    sys.procedures AS p
INNER JOIN
    sys.sql_modules AS m ON p.object_id = m.object_id
ORDER BY
    p.modify_date DESC;  
SELECT
    p.name AS ProcedureName,
    p.create_date AS CreationDate,
    p.modify_date AS LastModifiedDate,
    m.definition AS ProcedureDefinition
FROM
    sys.procedures AS p
INNER JOIN
    sys.sql_modules AS m ON p.object_id = m.object_id
WHERE
    m.definition LIKE '%xxxxx%'
ORDER BY
    p.modify_date DESC;  

2.NOT LIKE相关

DECLARE @p_source VARCHAR(256) = 'h5us4hz09';

-- 检查 @p_source 是否匹配任何指定的模式
IF @p_source NOT LIKE 'h5us4hz01%'
   AND @p_source NOT LIKE 'h5us4hz02%'
   AND @p_source NOT LIKE 'h5us4hz03%' -- 根据需要添加更多条件
BEGIN
    PRINT @p_source; -- 输出不匹配的源字符串
END

可以改成下面:

DECLARE @p_source VARCHAR(256) = 'h5us4hz09';

-- 使用一个临时表变量来存储模式
DECLARE @Patterns TABLE (Pattern VARCHAR(256));
-- 插入所有的模式
INSERT INTO @Patterns (Pattern) VALUES
('h5us4hz01%'),
('h5us4hz02%'),
('h5us4hz03%'); -- 在这里添加或删除模式

-- 采用交叉连接和聚合函数来查找任何匹配项
IF NOT EXISTS (
    SELECT 1
    FROM @Patterns
    WHERE @p_source LIKE Pattern
)
BEGIN
    PRINT @p_source;
END

 

 

发表评论

邮箱地址不会被公开。