I have a table, these two tables have two dates, one for start and one for end, I need to subtract the end date from the start date so that it returns the days and adds the result to a field automatically.
in your case what you have to do is make use of the function DATEDIFF(), with an exercise like the following it will give you the number of days between two dates
declare @FechaInicial Date = '01/05/2019'
declare @Fechafinal Date = '15/05/2019'
select DATEDIFF (DAY, @FechaInicial , @Fechafinal ) as resultado
if what you want to do is insert that value in a table of your db, what you can do is simply encapsulate that value in a variable and insert it in the field of your table, here is an exercise to guide you
declare @FechaInicial Date = '01/05/2019'
declare @Fechafinal Date = '15/05/2019'
BEGIN
BEGIN
CREATE TABLE #Result(
Valor int
)
END
declare @Valor int
set @Valor = DATEDIFF (DAY, @FechaInicial , @Fechafinal )
insert into #Result
select @Valor
END
in your case what you have to do is make use of the function
DATEDIFF()
, with an exercise like the following it will give you the number of days between two datesif what you want to do is insert that value in a table of your db, what you can do is simply encapsulate that value in a variable and insert it in the field of your table, here is an exercise to guide you
I hope I can guide you