1

I have custom type (Table type) in sql server 2008.

   CREATE TYPE RequestingDatesType AS TABLE
   (
   LeaveDate datetime,
   IsHoliday bit
   )

I have a store procedure

    CREATE PROCEDURE CreateLeaveRequest
    @EmployeeId int,
    @LeaveTypeId int,
    @LeaveDescription varchar(50)
    @TableVariable RequestingDatesType READONLY
    AS
      DECLARE @LeaveId INT

      //1st insert command
      INSERT INTO tblLeaveMaster(EmployeeId,LeaveTypeId,LeaveDescription)
      VALUES(@EmployeeId,@LeaveTypeId,@LeaveDescription)
      SET @LeaveId = SCOPE_IDENTITY()

      //2nd insert command
      INSERT INTO tblLeaveDetails(LeaveId,LeaveDate,IsHoliday)
      VALUES(@LeaveId, LeaveDate(*from custom type*), IsHoliday(*from custom type*))

My question is how can i insert values for 2nd insert command

4

1 回答 1

1

你必须使用这样的东西:

//2nd insert command
  INSERT INTO tblLeaveDetails(LeaveId,LeaveDate,IsHoliday)
  SELECT @LeaveId, LeaveDate, IsHoliday FROM @TableVariable
于 2013-09-14T08:11:59.460 回答