ale
ale

Reputation: 3431

Compare column value with result from stored procedure

I need compare in the where if the property boleta.c_Fk_CodPeriodo is equal to return value of SP dbo.paBltPeriodoBuscarUnico3 @fecha. The SP return value like '1011', '0711', etc..

SELECT 
   localizacion.c_Fk_IdBoleta
FROM 
   Blt_Boleta as boleta, Fnc_Localizacion as localizacion
WHERE 
   boleta.c_Pk_IdBoleta = localizacion.c_Fk_IdBoleta 
   AND localizacion.si_CodAsa = @id_Asa 
   AND  boleta.c_Fk_CodPeriodo = exec  dbo.paBltPeriodoBuscarUnico3 @fecha

The problem in exec says, syntax error in exec... so

How can I do this??

Upvotes: 1

Views: 1247

Answers (2)

Cade Roux
Cade Roux

Reputation: 89661

DECLARE @output AS varchar(4);
exec @output = dbo.paBltPeriodoBuscarUnico3 @fecha;

 SELECT 
                         localizacion.c_Fk_IdBoleta
                    FROM 
                         Blt_Boleta as boleta, Fnc_Localizacion as localizacion
                    WHERE 
                         boleta.c_Pk_IdBoleta = localizacion.c_Fk_IdBoleta 
                         AND localizacion.si_CodAsa = @id_Asa 
                         AND  boleta.c_Fk_CodPeriodo = @output

Upvotes: 1

Martin Smith
Martin Smith

Reputation: 453278

You would need to call the stored procedure first and assign the result to a variable then use the variable in the query.

You can't use stored procedures like that.

Upvotes: 1

Related Questions