为什么...
exec p_chePrice '2','wuweia','2007425131642a' 正确执行
exec p_chePrice '2','wuweia','a2007425131642' 正确执行exec p_chePrice '2','wuweia',a2007425131642 正确执行
exec p_chePrice '2','wuweia',2007425131642a 错误提示:
消息 102,级别 15,状态 1,第 1 行
'a' 附近有语法错误。
-----------------------------------------------------------------
-------下面附上我的存储过程
-----------------------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go/*修改价格*/
ALTER procedure [dbo].[p_chePrice](@price varchar(10),@buyName varchar(50),
@orderName varchar(100))
as
begin
if(cast(@price as int)='2')
update orderbuy set bPrice=product.pBigPrice
from (select pSmlPrice,pBigPrice,pVipPrice,pNo from product)product
where orderbuy.bpNo=product.pNo and buyname=''+@buyName+''
and orderName=''+@orderName+''
else
if(cast(@price as int)='3')
update orderbuy set bPrice=product.pVipPrice
from (select pSmlPrice,pBigPrice,pVipPrice,pNo from product)product
where orderbuy.bpNo=product.pNo and buyname=''+@buyName+''
and orderName=''+@orderName+''
else
update orderbuy set bPrice=product.pSmlPrice
from (select pSmlPrice,pBigPrice,pVipPrice,pNo from product)product
where orderbuy.bpNo=product.pNo and buyname=''+@buyName+''
and orderName=''+@orderName+''
end
exec p_chePrice '2','wuweia','2007425131642a' 正确执行
exec p_chePrice '2','wuweia','a2007425131642' 正确执行exec p_chePrice '2','wuweia',a2007425131642 正确执行
exec p_chePrice '2','wuweia',2007425131642a 错误提示:
消息 102,级别 15,状态 1,第 1 行
'a' 附近有语法错误。
-----------------------------------------------------------------
-------下面附上我的存储过程
-----------------------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go/*修改价格*/
ALTER procedure [dbo].[p_chePrice](@price varchar(10),@buyName varchar(50),
@orderName varchar(100))
as
begin
if(cast(@price as int)='2')
update orderbuy set bPrice=product.pBigPrice
from (select pSmlPrice,pBigPrice,pVipPrice,pNo from product)product
where orderbuy.bpNo=product.pNo and buyname=''+@buyName+''
and orderName=''+@orderName+''
else
if(cast(@price as int)='3')
update orderbuy set bPrice=product.pVipPrice
from (select pSmlPrice,pBigPrice,pVipPrice,pNo from product)product
where orderbuy.bpNo=product.pNo and buyname=''+@buyName+''
and orderName=''+@orderName+''
else
update orderbuy set bPrice=product.pSmlPrice
from (select pSmlPrice,pBigPrice,pVipPrice,pNo from product)product
where orderbuy.bpNo=product.pNo and buyname=''+@buyName+''
and orderName=''+@orderName+''
end
------------------------------------------------
第三个参数为字符型,应该加上引号
这个为什么可以?
exec p_chePrice '2','wuweia',a2007425131642 正确执行
exec p_chePrice '2','wuweia',2007425131642a 第一条语句到所以正确,是因为字串的第一个字符为a,所以系统将其视为字符串来处理
第二条语句的第一个字符为2,系统将共视为数值型来处理