Sql server抱怨这个IF NOT EXISTS语句,说关键字'OR'附近有'错误的语法'.
我的查询:
IF NOT EXISTS ( (SELECT * FROM Users where userID = 1) OR (SELECT * FROM sales WHERE saleID = 1) ) BEGIN // blah blah blah END
Steven A. Lo.. 8
试试这种方式
IF NOT EXISTS (SELECT 1 FROM Users where userID = 1) AND NOT EXISTS (SELECT 1 FROM sales WHERE saleID = 1) BEGIN -- blah blah blah END
或者,如果你坚持分离:
IF NOT ( EXISTS (SELECT 1 FROM Users where userID = 1) OR EXISTS (SELECT 1 FROM sales WHERE saleID = 1) ) BEGIN -- blah blah blah END
EXISTS运算符采用单个select语句并检查任何结果(因此您可以使用常量1而不是*或列名称,它更有效)
试试这种方式
IF NOT EXISTS (SELECT 1 FROM Users where userID = 1) AND NOT EXISTS (SELECT 1 FROM sales WHERE saleID = 1) BEGIN -- blah blah blah END
或者,如果你坚持分离:
IF NOT ( EXISTS (SELECT 1 FROM Users where userID = 1) OR EXISTS (SELECT 1 FROM sales WHERE saleID = 1) ) BEGIN -- blah blah blah END
EXISTS运算符采用单个select语句并检查任何结果(因此您可以使用常量1而不是*或列名称,它更有效)