更新时间:2022-11-27 15:43:08
该错误告诉您是您的子查询之一,但我不认为这些子查询是导致错误的原因.如果您使用 and 'exist'(或 'notexist' ),您也可以使用 TOP 1,因为您只需要检查一行.
The error tells you that one of your subqueries, but i don't think these subqueries are the one that give the error. If you use and 'exist' ( or 'not exist' ) you can also use TOP 1, because you only need to check one row.
这意味着您可以使用:
WHEN NOT EXISTS(SELECT TOP 1 1
FROM defs WITH(NOLOCK)
WHERE defaultname = @DEFAULT_CURRENCY
AND defaultvalue= @currency)
OR NOT EXISTS( SELECT TOP 1 1
FROM supp WITH(NOLOCK)
WHERE pint = @ID
AND currency= @currency)
但这不是导致您出错的原因.此示例代码执行相同的操作并且工作正常:
But this is not what is causing your error. This example code does that same and works fine:
declare @table1 table (
id int,
value nvarchar(100)
)
declare @subquery table (
id int,
value nvarchar(100)
)
insert into @table1 values (1, 'one')
insert into @table1 values (2, 'two')
insert into @table1 values (3, 'three')
insert into @subquery values (1, 'also one')
insert into @subquery values (3, 'also three')
insert into @subquery values (5, 'also five')
select * from @table1 sourceTable
where not exists (select 1 from @subquery where id = sourceTable.id)
and not exists (select 1 from @subquery where value = sourceTable.value)
所以我认为它必须在您查询的另一部分.
So I think it must be in another part of your query.