if object_id('tempdb..#TempMaxPrice') is not null
drop table #TempMaxPrice
create table #TempMaxPrice
(
PtypeId varchar(25),
MaxPrice numeric(18,4))
declare @a varchar(10) ,@b varchar(10)
set @a=1.02
set @b=1.06Insert into #TempMaxPrice(PtypeId,MaxPrice)
select PtypeId, MAX(Price) from GoodsStocks group by PtypeId update Ptype set preprice3=@a *(select MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeid)
错误提示如下:(所影响的行数为 3193 行)服务器: 消息 512,级别 16,状态 1,行 23
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
语句已终止。
drop table #TempMaxPrice
create table #TempMaxPrice
(
PtypeId varchar(25),
MaxPrice numeric(18,4))
declare @a varchar(10) ,@b varchar(10)
set @a=1.02
set @b=1.06Insert into #TempMaxPrice(PtypeId,MaxPrice)
select PtypeId, MAX(Price) from GoodsStocks group by PtypeId update Ptype set preprice3=@a *(select MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeid)
错误提示如下:(所影响的行数为 3193 行)服务器: 消息 512,级别 16,状态 1,行 23
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
语句已终止。
from #tempmaxprice a,ptype b where a.ptypeid=b.typeid
它返回了多個值
select MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeid
一次返回的是多行MaxPrice。所以错误
update Ptype
set preprice3=@a* b.MaxPrice
from Ptype a join #tempmaxprice b on a.typeid=b.ptypeid
update a set a.preprice3=@a*b.MaxPrice from Ptype a, #tempmaxprice b where a.ptypeid=b.typeid
总记录有三千多行了。。但
总记录有三千多行了。。但------------------
1:這三千多行 MaxPrice 是不是重復的select distinct MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeid2: 取最大的,或最小的select min(MaxPrice)as MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeid
总记录有三千多行了。。但-------------------------你的意思是怀疑数据没那么多?那再查这个语句,看看有没问题,是否缺了限制条件等:--Insert into #TempMaxPrice(PtypeId,MaxPrice)
select PtypeId, MAX(Price) from GoodsStocks group by PtypeId
if object_id('tempdb..#TempMaxPrice') is not null
drop table #TempMaxPricedeclare @a varchar(10) ,@b varchar(10)set @a=1.02 --手工输入点数,并赋值点数给局布变量@a
set @b=1.06 --手工输入点数,并赋值点数给局布变量@bcreate table #TempMaxPrice
(
PtypeId varchar(25),
MaxPrice numeric(18,4)
)
insert into #TempMaxPrice(PtypeId,MaxPrice)SELECT PtypeId, MAX(Price) FROM GoodsStocks GROUP BY PtypeId
update b set preprice3=@a *a.MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeidupdate b set preprice4=@b *a.MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeidupdate ptype set preprice3=round(preprice3,2),preprice4=round(preprice4,2)
drop table #TempMaxPricedeclare @a varchar(10) ,@b varchar(10)set @a=1.02 --手工输入点数,并赋值点数给局布变量@a
set @b=1.06 --手工输入点数,并赋值点数给局布变量@bcreate table #TempMaxPrice
(
PtypeId varchar(25),
MaxPrice numeric(18,4)
)
insert into #TempMaxPrice(PtypeId,MaxPrice)SELECT PtypeId, MAX(Price) FROM GoodsStocks GROUP BY PtypeId
update b set preprice3=@a *a.MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeidupdate b set preprice4=@b *a.MaxPrice from #tempmaxprice a,ptype b where a.ptypeid=b.typeid--update ptype set preprice3=round(preprice3,2),preprice4=round(preprice4,2) update b set preprice3=round(b.preprice3,2),b.preprice4=round(b.preprice4,2) from ptype b,#tempMaxPrice a where b.typeid=a.ptypeid