0
I have this select
below, but when date is true
, he needs to bring all the records where the field OrdemServicos.DataConclusao
is different from null, and when it is false
needs to bring everyone where the OrdemServicos.DataConclusao
is equal to null, and when @data is null, needs to bring both, how to solve, it does not understand Is not null, I am putting in a dataset, for reports.
SELECT OrdemServicos.DataConclusao, OrdemServicos.ValorTotal, OrdemServicos.ClienteId, OrdemServicos.OrcamentoId, Marca.Descricao AS marca, Modelo.Descricao AS modelo, Clientes.Nome, Empresas.RazaoSocial, Veiculos.Placa, Veiculos.Cor
FROM OrdemServicos INNER JOIN
Empresas ON Empresas.Id = OrdemServicos.EmpresaId INNER JOIN
Clientes ON Clientes.Id = OrdemServicos.ClienteId INNER JOIN
Veiculos ON Veiculos.Id = OrdemServicos.VeiculoId INNER JOIN
Modelo ON Modelo.Id = Veiculos.ModeloId INNER JOIN
Marca ON Marca.Id = Veiculos.MarcaId
where (Clientes.id = @idcliente or @idcliente is null)
and (Empresas.id = @idempresa or @idempresa is null)
and (Veiculos.id = @idveiculo or @idveiculo is null)
and (CASE WHEN @data = 'true' THEN OrdemServicos.DataConclusao IS NOT NULL
WHEN @data = 'false' THEN ordemservicos.dataconclusao is null)
I’m trying to do to generate a report,
reportivew
, but he does not recognize theif
, and informs that the@data
must be declared.– Mariana
Why don’t you create a Trigger, a job, or a manual routine that creates this final table and in the report you just use the select command? SELECT * FROM table_final WHERE field_conditional = CASE WHEN 1, 2, 3, etc... ; with a conditional of 1,2,3 depending on the case of the @data variable, as in my first example?
– Heitor Scalabrini
Of course, in this routine you will need to create a verification column. If you can create something like this, I can create an example for you.
– Heitor Scalabrini
Thanks for the help, I got a north.
– Mariana