0

The table tblEffort has 3 columns EmployeeName, Effort, Date. I get the first 2 column values from a table type parameter and have to insert a common date for all these values.

  1. do not have the option to include timesheetdate in dtCSV
  2. There should be some other way than running an update again on the inserted columns right?

The below code gives the error - Must declare the table variable "@TimesheetDate"

CREATE TYPE dbo.SaveEffort_TableType AS TABLE
(
  EmployeeName varchar(200),
  Effort decimal(18,2)  
);
GO

CREATE PROCEDURE SaveEmployeeEffort
(     
 @TimesheetDate datetime,
 @dtCSV AS dbo.SaveEffort_TableType readonly
)
AS
BEGIN
 INSERT INTO tblEffort(EmployeeName,Effort,[Date]) 
 SELECT * FROM @dtCSV,@TimesheetDate
END

1 Answer 1

1

You need to put the variable into the SELECT clause, not the FROM clause

CREATE PROCEDURE SaveEmployeeEffort
(     
 @TimesheetDate datetime,
 @dtCSV AS dbo.SaveEffort_TableType readonly
)
AS
BEGIN
 INSERT INTO tblEffort(EmployeeName,Effort,[Date]) 
 SELECT EmployeeName,Effort, @TimesheetDate FROM @dtCSV
END
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.