【问题标题】:Stored Procedure for quick add用于快速添加的存储过程
【发布时间】:2019-03-13 16:19:07
【问题描述】:

您好,我正在尝试创建一个存储过程来快速添加联系人。我有多个表并相应地加入它们。我的参数是 StudentEmail、EmployeeName、ContactDetails 和 ContactType。如果有人可以帮助我,我在插入语句时遇到问题。

 Drop Procedure if exists usp_addQuickContacts
 Go
 Create Procedure usp_addQuickContacts
   @StudentEmail nchar(50) = NULL, 
   @EmployeeName nchar (50) = NULL, 
   @ContactDetails nchar (50) = NULL, 
   @ContactType nchar(50)  = NULL

AS
Begin
Insert Into StudentContacts
(
    ContactID,
    StudentID,
    ContactTypeID,
    ContactDate,
    EmployeeID,
    ContactDetails
            )
 From StudentInformation inner join StudentContacts 
 On StudentInformation.StudentID = StudentContacts.StudentID 
 Inner Join Employees 
 On StudentContacts.EmployeeID = Employees.EmployeeID

End
Go

【问题讨论】:

标签: sql-server tsql join stored-procedures parameters


【解决方案1】:

您的子查询缺少select

Insert Into StudentContacts (ContactID, StudentID, ContactTypeID, ContactDate, EmployeeID, ContactDetails)
    select . . . 
    From StudentInformation si inner join
         StudentContacts sc
         On si.StudentID = sc.StudentID inner join
         Employees e
         On sc.EmployeeID = e.EmployeeID;

. . . 用于列,可能来自基础表。您需要填写该部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-13
    • 2011-06-12
    • 1970-01-01
    • 2012-01-28
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    相关资源
    最近更新 更多