紧急!帮忙解决个SQL存储过程的出错问题!

来源:百度知道 编辑:UC知道 时间:2024/05/13 06:43:50
实现目标:处理表shanghai3的hprice字段,处理后的数据存入字段hfprice;
处理方法:检测到小数点后,如果再出现两个以上小数点,则删除第二个小数点后的字符,同时如果检测到“万”字,则处理后的数据乘10000,如果处理后的数据小于1000,则同样将处理后的数据乘10000;
处理结果:现在只处理一条记录测试用,数据'70.11.22万元/套' 预期处理结果为701100;
程序如下:
update shanghai3
set hprice='70.11.22万元/套' where id =1
exec h_price
go

create procedure h_price
as

declare @i int
declare @flag int
declare @n nvarchar(10)
declare @pstr nvarchar(30)
declare @npstr nvarchar(30)
declare @price double

set @i=1 //行 12
set @flag=0
select @pstr=hprice from shanghai3 where id=1

while (@i<len(@pstr))
begin
n=substring(@pstr,@i,1) //行 18
if 48<=unicode(@n)<=57 and @flag<2 //行 19
begin
@npstr=@npstr&@n
end
else if @n='.' and flag=0
begin
@npstr=@npstr&@n //行 25
@flag=@flag+1
end
else

update shanghai3
set hprice='70.11.22万元/套' where id =1
exec h_price
go
放在存储过程创建之后
18行改为set @n=substring(@pstr,@i,1)
19行改为if unicode(@n)<=57 and unicode(@n)>=48 and @flag<2
25跟30都是赋值语句前面欠set
36行改为if charindex('万',@pstr)>0
sql没有double类型@price声明为float类型
还有所有赋值都加set