且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据查询返回的结果将字符串插入SQL表

更新时间:2022-12-03 20:13:15

您的代码中几乎包含了它.只需将SELECT *更改为SELECT COUNT(*)即可.我将设置状态,然后执行插入操作.

You almost have it in your code. Just change the SELECT * to SELECT COUNT(*) and you've got it . I would set the status and then do the insert.

DECLARE @testStatus NVARCHAR(MAX);

IF (
    SELECT COUNT(*)
    FROM Table1
    WHERE Table1.Column1 = ''
) = 0
    SET @testStatus = 'Test Passed'
ELSE
    SET @testStatus = 'Test Failed'

INSERT INTO Table2 (FileName, Date, Result)
VALUES ('File1', GetDate(), @testStatus)