5
I’m not getting the result of a select
within a variable.
I want to add the column turno
inside my WHERE
. The problem is I get the value of @turnos
in the following 3 formats:
1 -
'A'
2 -
'A','B'
3 -
'A','B','C'
Current situation
set @tjt = (select sum(duracao) from tabela where fabrica = @fabrica)
Desired situation (with error)
set @tjt= (select sum(duracao) from tabela where fabrica = @fabrica and turno IN (@turnos))
I see that turno IN (@turnos)
does not work, and so I tried to put the select
all between quotation marks concatenating the variables as follows:
@query = '(select sum(duracao) from tabela where fabrica = '+@fabrica+'
and turno IN ('+@turnos+'))'
But I still don’t understand how to put the result of this @query
in the variable @tjt
.
Why don’t you select within the
in ()
? for example...in (select coluna from ..)
?– Bulfaitelo