I work with a system that has a very limited report builder. The reports are basically restricted to a SQL query.
I need to present a query in a report that, in my query, the user is being informed by a multi-selection parameter, I will explain better:
The user informs about which units he wants to view the report, suppose he selects units 1 and 2, then in the IN
clause:
Where CODIGO_UNIDADE In (1,2)
So far so perfect, the problem is that I need to present in the report which units the user reported in the parameters, and the only way I have to do this is by declaring a variable in SQL and capturing the parameter that the user reported: p>
DECLARE @UNIDADE VARCHAR (100)
Set @UNIDADE = (
Select NOME from UNIDADES
Where CODIGO_UNIDADE In (:UNIDADE_INFORMADA_PELO_USUÁRIO)
)
Select @Unidade As 'Unidade Informada'
As you may already be wondering, this can not be done, because as the subquery returns more than one value an error is returned:
Mensagem 512, Nível 16, Estado 1, Linha 3
A subconsulta retornou mais de 1 valor. Isso não é permitido quando a subconsulta segue um =, !=, <, <= , >, >= ou quando ela é usada como uma expressão.
What is the easiest way to do this? Considering the limitations (pass value to a variable) that I have in my report?