求高手帮忙看一个更新存储过程的错误!!在线等
ALTER Proc sp_User_Info_Temp
@userID int,
@userLoginPwd varchar(50),
@userName varchar(10),
@userEmail varchar(50)
As
Declare @SQL varchar(5000) -- 主语句
Set @SQL = 'update tbl_User_Info set '
if @userLoginPwd <> ' ' or @userLoginPwd is not null
Begin
Set @SQL = @SQL + ' userLoginPwd = ' + @userLoginPwd
End
if @userName <> ' ' or @userName is not null
Begin
Set @SQL = @SQL + ',userName = ' + @userName
End
if @userEmail <> ' ' or @userEmail is not null
Begin
Set @SQL = @SQL + ',userEmail = ' + @userEmail
End
Set @SQL = @SQL + ' where userID = ' + cast(@userID as varchar)
exec(@SQL)
------解决方案--------------------alter Proc sp_User_Info_Temp
@userID int,
@userLoginPwd varchar(50),
@userName varchar(10),
@userEmail varchar(50)
As
Declare @SQL varchar(5000) -- 主语句
Set @SQL = 'update tbl_User_Info set '
if @userLoginPwd <> ' ' or @userLoginPwd is not null
Begin
Set @SQL = @SQL + ' userLoginPwd = ' ' ' + @userLoginPwd+ ' ' ' '
End
if @userName <> ' ' or @userName is not null
Begin
Set @SQL = @SQL + ',userName = ' ' ' + @userName+ ' ' ' '
End
if @userEmail <> ' ' or @userEmail is not null
Begin
Set @SQL = @SQL + ',userEmail = ' ' ' + @userEmail+ ' ' ' '
End
Set @SQL = @SQL + ' where userID = ' + cast(@userID as varchar)
exec( @SQL)
--试试,方法不是很好