0

我有 2 张桌子,StudentRegsitre 和 Agenda,

议程表有 (AgendaId, MatirelId, InstructorId, ClassId, addedDate, Semester, StartTime, EndTime, DaySchedule) StudentRegsitre (Id, AgendaId, UserId)

需要通过从 ASP.NET C# 传递 studentId 检查 StartTime 、 EndTime、 DaySchedule 、 classid 来检查 studentRegsitre 中是否存在重叠
我试试这个:

GO
 Create procedure [dbo].[SP_OverLappingExists] (@AgendaId uniqueidentifier ,@UserId uniqueidentifier  )
 As Begin 
 Declare @CurrentAgendaId uniqueidentifier;
 declare @MatirelId uniqueidentifier;
 declare @InstructorId  uniqueidentifier;
 declare @ClassId  uniqueidentifier;
 declare @Semester nchar(10);
 declare @StartTime time(7);
 declare @EndTime time (7);
 declare @DaySchedule varchar(50);
 declare @UserIdNew uniqueidentifier;
 declare @AgendaIdNew uniqueidentifier;

        if exists (SELECT @CurrentAgendaId = Agenda.AgendaId,@MatirelId= Agenda.MatirelId,
              @InstructorId= Agenda.InstructorId,@ClassId= Agenda.ClassId,@Semester= Agenda.Semester,
              @StartTime= Agenda.StartTime,@EndTime= Agenda.EndTime,@DaySchedule= Agenda.DaySchedule, 
                         @UserIdNew= StudentReg.UserId, @AgendaIdNew= StudentReg.AgendaId 
    FROM         Agenda INNER JOIN
                          StudentReg ON Agenda.AgendaId = StudentReg.AgendaId
                           where StudentReg.UserId = @UserId
      )
      begin
      return 1 
      end 

但它在@currentAgendaId = Agenda.AgendaId 附近出现错误“'=' 附近的语法不正确”有什么帮助,如果有更好的想法,请与我分享。!

ps:是Study case。

4

1 回答 1

0

EXISTS查询不返回任何列,因此您不能将列值分配给变量。

这是使用星号指定所有列不会影响性能的一种情况。常见的用法是:

if exists ( select * from ... )

这相当于:

if exists ( select 42 from ... )
于 2012-06-09T14:33:49.217 回答