我需要一个查询来更新用户表。我在下面写了一个,它工作正常。但我需要根据 Proc 发送的参数更新特定属性,有人有什么好主意吗?
--table
users(userID,firstname,lastName,age,UserTypeID,classID,SectionID)
--SP
'CREATE Proc UpdateUsers
(
@pUserID int ,
@pFirstName varchar(50),
@pLastName varchar(50),
@pAge int,
@pUserTypeID int,
@pClassID int,
@pSectionID int
)
as
if not exists (select 'true' from Users where UserID=@pUserID)
begin
print ('operation cannot complete; No such User founded, please enter valid UserID')
return
end
if exists (select 'true' from UserTypes where UserTypeID=@pUserTypeID)
begin
if exists (select 'true' from SectionsClasses where ClassID=@pClassID and
SectionID=@pSectionID)
update users set FirstName=@pFirstName,
LastName=@pLastName,
Age=@pAge,
UserTypeID=@pUserTypeID,
ClassID=@pClassID,
SectionID=@pSectionID
where UserID=@pUserID
else
print ('operation cannot complete; No such Class OR Section founded, please enter valid ClassID AND DectionID')
end
else
print ('operation cannot complete; No such UserType founded')
GO'