用SQL Server编写过程中出现语法错误
我用SQL server 2000写了一个存储过程,代码如下:
CREATE PROCEDURE dbo.SPLogin
@UserCode smallint,
@Name varchar(20),
@PW varchar(12),
@UserName varchar(20) OUTPUT,
@SiteCode smallint OUTPUT,
@SiteName varchar(50) OUTPUT,
@CantonID char(4) OUTPUT
as
begin
declare @AdminKey varchar(12),
@EmphiseKey varchar(12)
select top 1 @AdminKey=AdminKey,
@CantonID=CantonID,
@EmphiseKey=EmphiseKey
from dbo.SystemSet
select @UserName=",@SiteCode=0,@SiteName="
if @UserCode=-3
begin
if @AdminKey=@PW return 0
else return 2
end
else if @UserCode=-2
begin
if @EmphiseKey=@PW return 0
else return 2
end
else if @UserCode=-1
begin
if not exists(select * from dbo.Site where SiteAdmin=@Name) return 1
else
begin
if not exists(select * from dbo.Site where SiteAdmin=@Name and PassKey=@PW) return 2
else
begin
select @SiteCode=SiteCode,
@SiteName=SiteName
from dbo.site
where SiteAdmin=@Name and PassKey=@PW
return 0
end
end
end
else if @UserCode>=0
begin
if not exists(select * from dbo.Employee where TCode=@UserCode) return 1
else
begin
if not exists(select * from dbo.Employee where TCode=@UserCode and PassKey=@PW) return 2
else
begin
select @UserName=a.TName,
@SiteCode=b.SiteCode,
@SiteName=b.SiteName
from dbo.Employee a,dbo.Site b and a.Tcode=@UserCode and a.PassKey=@PW
return 0
end
end
end
end
先检查语法时发现是少了一个where语句,现已解决。现有两个问题:
1、检查时提示出错:错误207:Invalid column name ',@SiteCode=0,@SiteName='.
Invalid column name 'SiteName'.
Invalid column name 'SiteName'.
Invalid column name 'SiteCode'.
,请问是何原因,谢谢!
2、请问在SQL Server中检查语法时如何定位错误位置,查找帮助。
谢谢!
[解决办法]
消息 207,级别 16,状态 3,过程 SPLogin,第 20 行
列名 ',@SiteCode=0,@SiteName=' 无效。
是这一句
select @UserName=",@SiteCode=0,@SiteName="
你想做什么功能,后面也没有from 表名称
[解决办法]
你先弄清语法先,select @UserName=",@SiteCode=0,@SiteName=" 是无效的语句
=后面是什么也没有,select也不完整。