简体   繁体   English

在 SQL 服务器中插入或更新具有 2 个子查询的表

[英]Inserting or Updating a table with 2 sub queries in SQL Server

I am having a hard time doing a 'INSERT INTO' with 2 sub queries in the WHERE clause.我很难在 WHERE 子句中使用 2 个子查询执行“INSERT INTO”。 I'm not sure wht I'm missing, it keep stating that an expression of non-boolean type specified in context where a condition is expected, near ';'.我不确定我错过了什么,它一直说明在预期条件的上下文中指定的非布尔类型的表达式,靠近';'。

This is my attempt at it:这是我的尝试:

INSERT INTO [Monitor].[dbo].[MonitorIncidents]
SELECT * 
FROM dbo.MonitorSource
WHERE (
    SELECT DISTINCT * 
    FROM Lookup.dbo.ServerInfo S 
    WHERE NOT EXISTS
    (
        SELECT 1  
        FROM Lookup.dbo.Facts F 
        WHERE F.FactsName = S.SrvName 
        AND W.DateTime > DATEADD(hour, -23, CURRENT_TIMESTAMP)
    )
)

Your WHERE clause is missing an operand like = , < , > , etc. You are just returning a field to WHERE wihout a comparison.您的WHERE子句缺少=<>等操作数。您只是将一个字段返回到WHERE而不进行比较。 Depending on what you want to do, extend your WHERE to include a comparison.根据您想要做什么,扩展您的WHERE以包含比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM