Luis Mata
Luis Mata

Reputation: 73

Exists fail into stored procedure

This code work:

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

but, into stored procedure return this error:

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.

Upvotes: 3

Views: 34

Answers (1)

Yogesh Sharma
Yogesh Sharma

Reputation: 50163

Use a single SELECT statement. The inner SELECT statement is unnecessary. I would re-write your query as:

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

Upvotes: 2

Related Questions