日期:2014-05-19  浏览次数:20553 次

!~~~~~~~~郁闷不知道错在那里!~~~~~~~~~~~
我写了一个存储过程创建没有问题
运行就有问题是什么原因啊
create   procedure   checkuser
@usertype   int,
@userinfo   varchar(200),
@userpwd   varchar(200)
as
begin
declare   @strSql   NVARCHAR(500)
if(@usertype> 0)
set   @strSql= 'SELECT   dbo.ayUser.UserID,dbo.ayUser.UserName,dbo.ayUser.UserEmail,dbo.ayUser.PassWordID,   dbo.ayPassWord.ayPassWordID,dbo.ayPassWord.ayPassWord   FROM   dbo.ayPassWord   INNER   JOIN   dbo.ayUser   ON   dbo.ayUser.PassWordID   =   dbo.ayPassWord.ayPassWordID   where   dbo.ayUser.username= '+@userinfo+ '   and   dbo.ayPassWord.ayPassWord= '+@userpwd
else
set     @strSql= 'SELECT   dbo.ayUser.UserID,dbo.ayUser.UserName,dbo.ayUser.UserEmail,dbo.ayUser.PassWordID,   dbo.ayPassWord.ayPassWordID,dbo.ayPassWord.ayPassWord   FROM   dbo.ayPassWord   INNER   JOIN   dbo.ayUser   ON   dbo.ayUser.PassWordID   =   dbo.ayPassWord.ayPassWordID   where   dbo.ayUser.userEmail= '+@userinfo+ '   and   dbo.ayPassWord.ayPassWord= '+@userpwd

EXECUTE   sp_executesql   @strSql
print   @usertype
print   @strSql
end


exec   checkuser   1, 'ddd ', '123456 '


服务器:   消息   207,级别   16,状态   3,行   1
列名   'ddd '   无效。


给点帮助啊

------解决方案--------------------
create procedure checkuser
@usertype int,
@userinfo varchar(200),
@userpwd varchar(200)
as
begin
declare @strSql NVARCHAR(500)
if(@usertype> 0)
set @strSql= 'SELECT dbo.ayUser.UserID,dbo.ayUser.UserName,dbo.ayUser.UserEmail,dbo.ayUser.PassWordID, dbo.ayPassWord.ayPassWordID,dbo.ayPassWord.ayPassWord FROM dbo.ayPassWord INNER JOIN dbo.ayUser ON dbo.ayUser.PassWordID = dbo.ayPassWord.ayPassWordID where dbo.ayUser.username= ' ' '+@userinfo+ ' ' ' and dbo.ayPassWord.ayPassWord= ' ' '+@userpwd+ ' ' ' '
else
set @strSql= 'SELECT dbo.ayUser.UserID,dbo.ayUser.UserName,dbo.ayUser.UserEmail,dbo.ayUser.PassWordID, dbo.ayPassWord.ayPassWordID,dbo.ayPassWord.ayPassWord FROM dbo.ayPassWord INNER JOIN dbo.ayUser ON dbo.ayUser.PassWordID = dbo.ayPassWord.ayPassWordID where dbo.ayUser.userEmail= ' ' '+@userinfo+ ' ' ' and dbo.ayPassWord.ayPassWord= ' ' '+@userpwd+ ' ' ' '

EXECUTE sp_executesql @strSql
print @usertype
print @strSql
end

------解决方案--------------------
--try
create procedure checkuser
@usertype int,
@userinfo varchar(200),
@userpwd varchar(200)
as
begin
declare @strSql NVARCHAR(500)
if(@usertype> 0)
set @strSql= 'SELECT dbo.ayUser.UserID,dbo.ayUser.UserName,dbo.ayUser.UserEmail,dbo.ayUser.PassWordID, dbo.ayPassWord.ayPassWordID,dbo.ayPassWord.ayPassWord FROM dbo.ayPassWord INNER JOIN dbo.ayUser ON dbo.ayUser.PassWordID = dbo.ayPassWord.ayPassWordID where dbo.ayUser.username= ' ' '+@userinfo+ ' ' ' and dbo.ayPassWord.ayPassWord= '+@userpwd
else
set @strSql= 'SELECT dbo.ayUser.UserID,dbo.ayUser.UserName,dbo.ayUser.UserEmail,dbo.ayUser.PassWordID, dbo.ayPassWord.ayPassWordID,dbo.ayPassWord.ayPassWord FROM dbo.ayPassWord INNER JOIN dbo.ayUser ON dbo.ayUser.PassWordID = dbo.ayPassWord.ayPassWordID where dbo.ayUser.userEmail= ' ' '+@userinfo+ ' ' ' and dbo.ayPassWord.ayPassWord= '+@userpwd

EXECUTE sp_exe