首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

!郁闷不知道错在那里!解决方案

2012-01-03 
!~~~~~~~~郁闷不知道错在那里!~~~~~~~~~~~我写了一个存储过程创建没有问题运行就有问题是什么原因啊create

!~~~~~~~~郁闷不知道错在那里!~~~~~~~~~~~
我写了一个存储过程创建没有问题
运行就有问题是什么原因啊
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_executesql @strSql
print @usertype


print @strSql
end

热点排行