当前位置: 代码迷 >> Sql Server >> sql存储过程有关问题,帮小弟我
  详细解决方案

sql存储过程有关问题,帮小弟我

热度:87   发布时间:2016-04-27 11:59:38.0
sql存储过程问题,帮我啊
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[getUserNamebb]
  @UserName varchar(100),
  @paww varchar(100),
@biaoshu varchar(100)
  as
  begin
declare @cishu int,@mon int,@uuid int,@StartTime datetime
set @uuid=0;
set @StartTime =(select getdate())

  select top 1 pe_pwdd,pe_sex,pe_nini,diqu1,diqu2,pe_UserId,addtime,pe_zhuye,pe_cishu
  from dbo.[useruser1] 
  where [email protected] and [email protected]
if @@rowcount>0
begin

select top 1 @uuid=pe_UserId
  from dbo.[useruser1] 
  where [email protected] and [email protected]
update useruser1 set pe_cishu=pe_cishu+1,[email protected] where [email protected]
exec('Select pe_jibie,pe_zeou,pe_Photo,pe_nianji,pe_zhuye,pe_zhaopian From ' + @biaoshu + ' Where [email protected]')
 
end  
else
return 1
  end
创建没一点问题,但是执行的时候,给上参数,就会提示


(1 行受影响)

(1 行受影响)
消息 137,级别 15,状态 2,第 1 行
必须声明标量变量 "@uuid"。

(1 行受影响)


为什么啊,大侠帮我

------解决方案--------------------
SQL code
ALTER PROCEDURE [dbo].[getUserNamebb]    @UserName varchar(100),    @paww varchar(100),    @biaoshu varchar(100)asbegin    declare @cishu int,@mon int,@uuid int,@StartTime datetime    set @uuid=0;    set @StartTime =(select getdate())    select top 1 pe_pwdd,pe_sex,pe_nini,diqu1,diqu2,pe_UserId,addtime,pe_zhuye,pe_cishu    from dbo.[useruser1]      where [email protected] and [email protected]    if @@rowcount>0    begin        select top 1 @uuid=pe_UserId          from dbo.[useruser1]            where [email protected] and [email protected]                  update useruser1 set pe_cishu=pe_cishu+1,[email protected] where [email protected]                declare @strSql nvarchar(2048)        set @strSql = 'Select pe_jibie,pe_zeou,pe_Photo,pe_nianji,pe_zhuye,pe_zhaopian From ' + @biaoshu + ' Where [email protected]'        execute sp_executesql @strSql,[email protected] int',@uuid    end       else    return 1end
------解决方案--------------------
探讨
啊,两位老大的答案都是正确的,能告诉我

set @strSql = 'Select pe_jibie,pe_zeou,pe_Photo,pe_nianji,pe_zhuye,pe_zhaopian From ' + @biaoshu + ' Where [email protected]'

execute sp_executesql @strSql,[email protected] int',@uuid……
  相关解决方案