日期:2014-05-18  浏览次数:20468 次

第一次写存储过程,出个错,各位高手看下
存储过程如下
CREATE PROCEDURE [dbo].[upt]  
@station varchar(5),  
@yeares int, 
@monthes int, 
@dayes int,  
@tave money,
@num int output
AS  

begin  
  declare @sql varchar(200)  

  If not exists(select 1 from [dbo].[tave] where [station] = @station and [yeares]=@yeares and [monthes]=@monthes and [dayes]=@dayes )  
  return 1  

  set @sql = ''  

  If not @tave Is Null
  set @sql = @sql + '[tave] = ' + @tave 

  If @sql = ''  
  return 2  


  EXEC ('Update [dbo].[tave] set ' + @sql + ' where [station] =' + @station + ' and [yeares]=' + @yeares + 'and [monthes]=' + @monthes + ' and [dayes]=' + @dayes )
  return 3  

end  
go  
-----------------------------
调用语句
declare @num int

exec dbo.upt '51053','2010','12','1',7,@num output
SELECT @num
------------------------------
出错信息
消息 235,级别 16,状态 0,过程 upt,第 39 行
无法将 char 值转换为 money。该 char 值的语法有误。


------解决方案--------------------
set @sql = @sql + '[tave] = ' + cast(@tave as varchar(100))