null パラメーターを使用して挿入ストアド プロシージャを作成したいのですが、そのパラメーターの値を渡すと、データベースに挿入または更新する必要があります。
私のストアドプロシージャは次のとおりです。
Create proc [dbo].[SP_InsertOrUpdateCourseDetails]
@CourseID int,
@Tab1Title nvarchar(250) = null,
@Tab1Description nvarchar(max) = null,
@Tab2Title nvarchar(250) = null,
@Tab2Description nvarchar(max) = null,
@Tab3Title nvarchar(250) = null,
@Tab3Description nvarchar(max) = null,
@Tab4Title nvarchar(250) = null,
@Tab4Description nvarchar(max) = null,
@Syllabus nvarchar(max) = null
As
Begin
If NOT EXISTS (Select * from CourseDetail Where CourseID=@CourseID )
Begin
Insert into CourseDetail(CourseID, Tab1Title, Tab1Description,
Tab2Title, Tab2Description,
Tab3Title, Tab3Description, Tab4Title, Tab4Description,
Syllabus)
values (@CourseID, @Tab1Title, @Tab1Description, @Tab2Title, @Tab2Description,
@Tab3Title, @Tab3Description, @Tab4Title, @Tab4Description, @Syllabus)
IF @@ERROR = 0 AND @@ROWCOUNT =1
Begin
Select top 1 CourseID from CourseDetail Order by CourseDetailID Desc
End
Else
Begin
Select 0
End
End
Else
Begin
Update CourseDetail
SET
Tab1Title = @Tab1Title,
Tab1Description = @Tab1Description,
Tab2Title = @Tab2Title,
Tab2Description = @Tab2Description,
Tab3Title = @Tab3Title,
Tab3Description = @Tab3Description,
Tab4Title = @Tab4Title,
Tab4Description = @Tab4Description,
Syllabus = @Syllabus
Where
CourseID = @CourseID
IF @@ERROR = 0 AND @@ROWCOUNT =1
Begin
Select top 1 CourseID from CourseDetail Order by CourseDetailID Desc
End
Else
Begin
Select 0
End
End
End