If there is a single row with the FLAG column containing "S" and another row containing the value "E", both meeting the filter defined in the WHERE clause, the code below returns what is requested.
-- código #1
SELECT @dataInicio= case when FLAG = 'E' then DTDIGIT else @dataInicio end,
@dataFim= case when FLAG = 'S' then EMISSAO else @dataFim end
from tabela
where ...;
Example:
-- código #2
CREATE TABLE Config (FLAG char(1), DTDIGIT date, EMISSAO date);
INSERT into Config values
('E', '20120303', NULL), ('S', NULL, '20120403');
declare @dataInicio date, @dataFim date;
SELECT @dataInicio= case when FLAG = 'E' then DTDIGIT else @dataInicio end,
@dataFim= case when FLAG = 'S' then EMISSAO else @dataFim end
from Config;
SELECT @dataInicio, @dataFim;
However, if there is more than one row with the same value for the FLAG column, the completion of variables is undetermined.
The FLAG field is stored where? What is a field in this context? Note that in the statement both "field" and "column" are cited. // How is the source table? // How are DTDIGIT and EMISSAL columns declared?
– José Diz
Good morning the flag field is a column that the only result of it is E or S (input or output) the emitted column and dtdigit are of type date,
– Leonardo Palmieri
It would be something +/-like IIF (FLAG = 'E', DTDIGIT OR FLAG = ’S'OUTPUT)
– Leonardo Palmieri