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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -