SQL 参数,传入参数和自己申明参数——异常抛出
ALTER PROCEDURE [dbo].[OA_RemoveProject] @Password nvarchar(30), --这是传入的参数 @ProjectNo nvarchar(8) AS DECLARE @ProjectId int --这是声明的参数。 DECLARE @Count int BEGIN IF UPPER(@Password)='FEIFEIDEMAO' BEGIN SET @Count=(SELECT COUNT(*) FROM DwProject WHERE ProjectNo=@ProjectNo) if @Count=1 BEGIN SET @ProjectId=(SELECT Id FROM DwProject WHERE ProjectNo=@ProjectNo) Delete From DwProject Where Id=@ProjectId Delete From DwTask Where LinkId=@ProjectId Delete From DwProjectRelatedPersonnel Where ProjectId=@ProjectId Delete From DwProjectQuestion Where ProjectId=@ProjectId Delete From DwProjectFile Where ProjectId=@ProjectId END ELSE IF @Count>1 RAISERROR(N'项目编码对应多个主键ID,无法删除!',11,5)WITH NOWAIT ELSE RAISERROR(N'未找到项目编号!',11,5)WITH NOWAIT END ELSE RAISERROR(N'密码错误,重新执行!',11,5)WITH NOWAIT END
需求:ID主键,非查询不可取到。但是ProjectNo可以看到。实现通过ProjectNo删除数据,以及关联表数据。(参数是 密码和要删除的项目编号)