Return 1 or 0 depending on the result of the query

1

I have the following query

Select L.idtipolocalidad from Localidad L 
inner join RecepcionDetalleAbierta RDA on RDA.idLocalidadAlmacenado = L.IdLocalidad 
inner join Localidad L1 on RDA.IdLocalidad = L1.IdLocalidad where l1.Codigo = 'PREC36'
group by L.IdTipoLocalidad'

It results in a 5 but what I try to do is that if it brings 5 save to a variable 1 otherwise 0

I hope you can help me.

This is my attempt but I do not have it left

SET @vEnvioCompleto = (SELECT CASE WHEN L.IdTipoLocalidad = 5 THEN 1 ELSE 0 END FROM RecepcionDetalleAbierta RDA
                    INNER JOIN Localidad L ON L.IdLocalidad = RDA.IdLocalidadAlmacenado
                    inner join Localidad L1 on RDA.IdLocalidad = L1.IdLocalidad
                    WHERE L.Codigo = 'PREC36')

Thanks

    
asked by Javier fr 23.03.2018 в 17:22
source

1 answer

0

If you only want to see the result in the management studio then you have to do after the assignment to the variable:

Select @vEnvioCompleto

A recommendation on the set of the variable @vEnvioCompleto you have to limit the result set to 1 only result so that you do not get an error if at some point the query comes back to return more than one record. You can do that using Top

 set @vEnvioCompleto = (select top 1 ... el resto de tu consulta)

link

If the result you need to read from an application you could create a Stored Procedure with your query and call Stored from the application.

link

To run the stored and read the information that comes back, that depends on the application that makes the call.

    
answered by 04.04.2018 в 21:30