I need to go through a whole table and depending on its content insert that data somewhere else that I imagine I could use a switch , but I have problems to reference it to the variable I want.
I need to recognize the value of [Charge / Credit] and depending on whether it is "-" or "+" save it [Amount] in variable @abono or @cargo .
IF OBJECT_ID('tempdb..#stats_ddl') is not null DROP TABLE stats_ddl
GO
CREATE TABLE #stats_ddl (
[Cuenta] varchar(max),
[Fecha] varchar(50), --
[Hora] varchar(50),
[Suc] varchar(50),
[Descripcio] varchar(max),
[Cargo/Abono] varchar(50),
[Importe] varchar(50),
[Saldo] varchar(50),
[Referencia] varchar(50),
[Concepto / Referencia Interbancaria] varchar(max) --
);
Go
declare @cargo varchar(max) = '',
@count int = 0,
@abono varchar(max) = ''
bulk insert erpsamfinanzas.dbo.#stats_ddl
from 'C:\SAM\SamFinanzas\Facturas_20180822144927_20180822144927.csv'
with ( firstrow = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n')
--select * from stats_ddl
declare @count int = 0,
@countb int = 1
set @count = (select count( * ) from #stats_ddl)
while @countb <= @count
begin
DECLARE @fechaMov VARCHAR(50) = (SELECT TOP(1) [Cargo/Abono] FROM #stats_ddl);
PRINT 'fecha' + @fechaMov + ' ' + CONVERT(VARCHAR, @count);
-- por quiero meter el switch y que me tome cargo/abono y dependiendo de lo que sea me almacene en cargo u abono la columa de importe
DELETE TOP (1) FROM #stats_ddl
SELECT @count = COUNT(*) FROM #stats_ddl;
end