日期:2014-05-18 浏览次数:20390 次
create procedure sp_upd @m_file varchar(10) as BEGIN DECLARE @m_str varchar(10) set @m_str=substring('+@m_file+',1,3) if(@m_str='新产品') begin update kh set kh.@m_file=cast((@m_file.价格/10000) as numeric(6,2)) from kh where kh.编号=@m_file.编号 end else begin update kh set kh.@m_file=cast((@m_file.旧价格/10000) as numeric(8,2)) from kh where kh.编号=@m_file.编号 end END
------解决方案--------------------
create procedure sp_upd @m_file varchar(10) as BEGIN DECLARE @m_str varchar(10) set @m_str=substring('+@m_file+',1,3) declare @col varchar(32) set @col =?---这里获取你的列名称 declare @price_old money,@price_new money set @price_old=?---获取价格(利用拆分字符串函数 拆分@m_file,从中获取 旧价格) set @price_new=?---获取价格(利用拆分字符串函数 拆分@m_file,从中获取 价格) declare @code varchar(32) set @code =?---获取编号(利用拆分字符串函数 拆分@m_file,从中获取 编号) declare @sql varchar(max) if(@m_str='新产品') begin set @sql ='update kh set '+@col+'= cast(('+@price_new+'/10000) as numeric(6,2)) from kh where kh.编号='''+@code+'''' exec(@SQL) --update kh set kh.具体的列名=cast((@m_file.价格/10000) as numeric(6,2)) from kh where kh.编号=@m_file end else begin SET @sql =' update kh set '+@col+'=cast(('+@price_old+'/10000) as numeric(8,2)) from kh where kh.编号='''+@code+'''' exec (@SQL) --update kh set kh.具体的列名=cast((@m_file.旧价格/10000) as numeric(8,2)) from kh where kh.编号=@m_file end END
------解决方案--------------------
变量声明:
DECLARE @m_file varchar(10)
------解决方案--------------------
除了前面的语句错误
两个update语句有问题
说一说LZ想用存储过程干什么?