存储过程
CREATE PROC UsersInSert @UserCD varchar(50), @UserName varchar(50), @UserType varchar(10), @UserVar varchar(10) AS declare @IsUser int,@select_sql nvarchar(200),@Updat_sql nvarchar(400),@IsSuccess int Begin set @select_sql=N'select @IsUser=count(UserId) from SUser where UserId='+@UserCD; exec sp_executesql @select_sql,N'@IsUser int out',@IsUser out if(@IsUser>0) begin set @Updat_sql=N'update SUser set UserName='''+@UserName+''',UserType='''+@UserType+''',Ver='''+@UserVar+''' where UserId='+@UserCD; end else begin set @Updat_sql=N'insert into SUser(UserId,UserName,UserType,Ver)values('+@UserCD+','+@UserName+','+@UserType+','+@UserVar+')'; end exec sp_executesql @Updat_sql --exec sp_executesql N'select @IsSuccess='+@@ROWCOUNT+'',N'@IsSuccess int out',@IsSuccess out --print @IsSuccess End exec UsersInSert '00012','000','1','1'