c# - Compare multi rows with a row in SQL Server 2008 -
i have asp.net c# project, study case, "a university website"
i have table called agenda , contain 9 columns
[agendaid] uniqueidentifier [matirelid] [instructorid] [classid] [addeddate] [semester] [starttime] [endtime] [dayschedule] and shows material available, instructor, in days, in time start , end, in class, in same semester.
what need: when add new row, should check if overlapping of existing row. if have overlapping , give me error.
ps: instructorid, matirelid , classid foreign keys other tables.
prefer make in stored procedure in sql server 2008.
kindly & best regards
assuming all columns have match duplicate - you'd use this:
create procedure dbo.insertnewrow @agendaid uniqueidentifier., @matirelid int, -- did not mention *types* columns have - adapt needed! @instructorid int, @classid int, @addeddate datetime, @semester int @starttime time(7), @endtime time(7), @dayschedule int begin if exists (select * dbo.agenda matirelid = @matirelid , instructorid = @instructorid , classid = @classid , semester = @semester , starttime = @starttime , endtime = @endtime , dayschedule = @dayschedule) raiserror ....... return insert dbo.agenda(agendaid, matirelid, instructorid, classid, addeddate, semester, starttime, endtime, dayschedule) values(@agendaid, @matirelid, @instructorid, @classid, @addeddate, @semester, @starttime, @endtime, @dayschedule) end read the excellent msdn documentation learn how call raiserror cause error thrown stored procedure!
Comments
Post a Comment