In a simple query, I have a table with the following structure:
SELECT * FROM [SAMX].[dbo].[REPORTE_ESTADO_CUENTA_GLOBAL] where intencion_id=1657 ORDER BY intencion_id,fecha
I need to fill in the column with a '0' or a '1' depending on whether the query contains an initial charge for the contract as follows: - if it does not contain it, account must be '0' - if it contains it, you should check the status of that record - if the status is 'C', account must remain '0' - if the status is '', account must be '1', and all records from here, account must be '1'
I tried using a variable, but I can not combine a SELECT
of value assignment with one of data acquisition.
DECLARE @var1 int;
select @var1=0;
SELECT @var1=(CASE tipomovimiento WHEN 'Cargo Inicial del Contrato' THEN 1 ELSE 0 END)
,@var1 AS cuenta,[fecha],[tipomovimiento],[abono],[cargo],[estatus],[intencion_id] FROM REPORTE_ESTADO_CUENTA_GLOBAL where intencion_id=1657 ORDER BY intencion_id,fecha
Could you suggest a solution?