ALTER PROCEDURE dbo.fileInfo_storedProcess
@CMD char(10),
@loginname nvarchar(50)='',
@articleno nvarchar(50)='',
@pagecount int=0,
@figcount int=0,
@tablecount int=0,
@equcount int=0,
@note ntext='',
@newfile bit='0',
@onlineearly bit='0',
@revise bit='0',
@vouchar bit='0',
@datetime1 datetime,
@datetime2 datetime,
@sourcepath nvarchar(50)='',
@purposepath nvarchar(50)=''AS if(@CMD='SELECT')

    BEGIN
DECLARE @datetime3 datetime

set @datetime3='1900-01-01'

DECLARE   @sqlwhere varchar(4000) 
set @sqlwhere='select *from FileInfor where 1=1 '
if(@loginname<>'')
begin
set @sqlwhere=@sqlwhere+' and  LoginName='''+@loginname+''''

end 
if(@articleno<>'')
begin
set @sqlwhere=@sqlwhere+' and ArticleNo='''+@articleno+''''
end
if(@pagecount<>0)
begin
set @sqlwhere=@sqlwhere+ ' and PageCount='''+@pagecount+''
 print(@sqlwhere)
end
if(@figcount<>0)
begin
 set @sqlwhere=@sqlwhere+ ' and FigCount= '+@figcount
end
if(@tablecount<>0)
begin
set @sqlwhere=@sqlwhere+' and TableCount='+@tablecount
end
if(@equcount<>0)
begin
set @sqlwhere=@sqlwhere+' and EquCount='+@equcount
end
if(@newfile<>'')
begin
 set @sqlwhere=@sqlwhere+' and NewFile='''+ltrim(@newfile)+''''
end
if(@onlineearly<>'')
begin
 set @sqlwhere=@sqlwhere+' and OnLineearly='''+ltrim(@onlineearly)+''''
end
if(@revise<>'')
begin
 set @sqlwhere=@sqlwhere+' and Revise='''+ltrim(@revise)+''''
end
if(@vouchar<>'')
begin
 set @sqlwhere=@sqlwhere+' and Vouchar='''+ltrim(@vouchar)+''''
end
if(@datetime1<>@datetime3 and @datetime2<>@datetime3)
begin
 set @sqlwhere=@sqlwhere+' and DateTime>='''+cast(@datetime1 as varchar)+'''' +' and DateTime<='''+cast(@datetime2 as varchar)+''''

 end
 print(@sqlwhere)
 exec(@sqlwhere)

END
else if(@CMD='INSERT')
  BEGIN
  INSERT INTO  FileInfor(LoginName,ArticleNo,PageCount,TableCount,EquCount,Note,Newfile,OnLineearly,Revise,Vouchar,DateTime,SourePath,PurposePath) values(@loginname,@articleno,@pagecount,@tablecount,@equcount,@note,@newfile,@onlineearly,@revise,@vouchar,@datetime1,@sourcepath,@purposepath)
  
  END

RETURN 
输入
@CMD = SELECT, @loginname = rentao, @articleno = <DEFAULT>, @pagecount = 8, @figcount = <DEFAULT>, @tablecount = <DEFAULT>, @equcount = <DEFAULT>, @note = <DEFAULT>, @newfile = 1, @onlineearly = 0, @revise = 0, @vouchar = 0, @datetime1 = 2007/10/12, @datetime2 = 2007/10/17, @sourcepath = <DEFAULT>, @purposepath = <DEFAULT> ).Syntax error converting the varchar value 'select *from FileInfor where 1=1  and  LoginName='rentao' and PageCount='' to a column of data type int.
没有行受影响。
(返回 0 行)
@RETURN_VALUE = 
完成 dbo."fileInfo_storedProcess" 运行。
主要是这一句
if(@pagecount<>0)
begin
set @sqlwhere=@sqlwhere+ ' and PageCount='''+@pagecount+''
print(@sqlwhere)
end
请高手指点