sql - Setting Datediff as a variable in a stored procedure -
i trying insert new holiday holidays table, have duration column want calculated inside stored procedure. have used date diff work out days want declare date diff variable , print variable values of insert statement. statement below getting error: column name 'startdate' specified more once in set clause or column list of insert. column cannot assigned more 1 value in same clause. modify clause make sure column updated once. if statement updates or inserts columns view, column aliasing can conceal duplication in code.
create procedure sprequestholiday @employeeid int, @startdate date, @enddate date, @duration int /* name: sprequestholiday description: inserts requested holiday holidays table */
as
select datediff(day,@startdate,@enddate) diffdate begin insert holidays(employeeid, startdate, enddate, duration,startdate) values(@employeeid, @startdate, @enddate, 'diffdate','pe') end
try this
declare @datediff int select @datediff = datediff(day,@startdate,@enddate) insert holidays(employeeid, startdate, enddate, duration, pe) --< columns name pe values(@employeeid, @startdate, @enddate, @datediff,'pe')
or
insert holidays(employeeid, startdate, enddate, duration, pe) --< columns name pe values(@employeeid, @startdate, @enddate, datediff(day,@startdate,@enddate),'pe')
Comments
Post a Comment