I am working with this table in SQL Server 2014:
create table suceso
(
id int identity (1,1) not null,
codMod varchar (10) not null,
fecha date not null
constraint pk_suceso primary key (id)
);
go
And this is the stored procedure:
create procedure sp_insNuevoModulo
@codMod varchar (10)
as
begin
declare @fecha date;
set @fecha = (select fecha from suceso where codMod = @codMod and fecha =
(select convert (varchar(10), GETDATE(),103)));
if (@fecha = null)
insert into suceso values (@codMod, (select convert (varchar(10), GETDATE(),103)));
end
go
In short, if the return becomes null, I would have to add a new datum, otherwise, nothing.
when I run:
exec sp_insNuevoModulo 'COD01';
I get the message: "Commands completed correctly." but when consulting the table is empty.