存在失败进入存储过程

Exists fail into stored procedure

此代码有效:

declare @IDArticulo int = 12
declare @DescripcionArticuloVEL varchar(150) = (select top 1 DescripcionArticulo 
from TabVentasEnLineaDetalle where IDArticulo=@IDArticulo and exists (select DescripcionArticulo 
from TabVentasEnLineaDetalle where IDArticulo=@IDArticulo))
print @DescripcionArticuloVEL

但是,进入存储过程return出现这个错误:

Msg 116, Level 16, State 1, Procedure SPMaestroArticulos, Line 43
You can only specify an expression in the selection list when the subquery is not specified with EXISTS.

使用单个 SELECT 语句。内部 SELECT 语句是不必要的。我会将您的查询重写为:

SELECT TOP (1) @DescripcionArticuloVEL = DescripcionArticulo 
FROM TabVentasEnLineaDetalle 
WHERE IDArticulo = @IDArticulo;