0

我正在尝试从 EmployeeMaster 检索名称并插入 LeaveCarryForwardTemp .. 我写了这个查询.. 但它返回一个空值.. 请建议..

   (    
         @CreatedUserID as nvarchar(9)
        ,@CalendarYear as numeric(18, 0)    
   )
    AS

    BEGIN

    Select

        A.EmployeeID,B.Name  as EmpName             
        From HRLeaveCarryForwardTemp A
        Join HREmployeeMaster B On A.EmployeeID = B.EmployeeID
        Where A.EmployeeID = B.EmployeeID

        Delete dbo.HrLeaveCarryForwardTemp
        Where UserID = @CreatedUserID 

        INSERT INTO [dbo].[HrLeaveCarryForwardTemp]
           ( [UserID]
            ,[EmployeeID]
            ,[CalendarYear]
            ,[LeaveCarryForward]
            ,[Status]
            )
        Select 
             @CreatedUserID             
            ,[EmployeeID]
            ,@CalendarYear
            ,[LeaveCarryForward]
            ,[Status]           
        From dbo.[HRLeaveCarryForward]
        Where CalendarYear =@CalendarYear

    END
4

2 回答 2

0

因此,您必须将 Name 或 Id 保存在变量中,并将变量传递给 Insert 查询,如下所示...

DECLARE @EmpID int

Select  @EmpID = A.EmployeeID
        From HRLeaveCarryForwardTemp A
        Join HREmployeeMaster B On A.EmployeeID = B.EmployeeID
        Where A.EmployeeID = B.EmployeeID

-- 或者如果你想要名字然后

Declare @EmpName varchar(50)

Select  @EmpName = B.Name 
        From HRLeaveCarryForwardTemp A
        Join HREmployeeMaster B On A.EmployeeID = B.EmployeeID
        Where A.EmployeeID = B.EmployeeID

现在根据您的要求将变量传递给插入查询...

于 2013-03-20T09:24:15.903 回答
0

您正在与 HREmployeeMaster 一起加入 HRLeaveCarryForwardTemp,并从 HRLeaveCarryForward 表中插入..??

于 2013-03-20T04:31:20.267 回答