IF EXISTS( Select Name
From sysobjects
Where Name =N'QueryPriceInList'
And Type = 'P')
DROP PROCEDURE QueryPriceInList
GO
CREATE PROCEDURE QueryPriceInList @SelectPrice Decimal(18,6), @MaxPrice Decimal(18,6),@PriceRangePercent Decimal(18,6)OUTPUT
AS
Select @PriceRangePercent = (@SelectPrice - @MaxPrice)/@MaxPrice
GO
Exec QueryPriceInList '10','100','@PriceRangePercent'执行时,
服务器: 消息 8114,级别 16,状态 4,过程 QueryPriceInList,行 0
将数据类型 varchar 转换为 decimal 时出错。
请问该如何解决?
From sysobjects
Where Name =N'QueryPriceInList'
And Type = 'P')
DROP PROCEDURE QueryPriceInList
GO
CREATE PROCEDURE QueryPriceInList @SelectPrice Decimal(18,6), @MaxPrice Decimal(18,6),@PriceRangePercent Decimal(18,6)OUTPUT
AS
Select @PriceRangePercent = (@SelectPrice - @MaxPrice)/@MaxPrice
GO
declare @PriceRangePercent decimal(18,6)
Exec QueryPriceInList '10','100',@PriceRangePercent
而你传入了'@PriceRangePercent',肯定错了
如果@PriceRangePercent是个decimal参数
--Exec QueryPriceInList '10','100','@PriceRangePercent'
------------------------------------------------Exec QueryPriceInList '10','100',@PriceRangePercent
From sysobjects
Where Name =N'QueryPriceInList'
And Type = 'P')
DROP PROCEDURE QueryPriceInList
GO
CREATE PROCEDURE QueryPriceInList @SelectPrice Decimal(18,6), @MaxPrice Decimal(18,6),@PriceRangePercent Decimal(18,6)OUTPUT
AS
Select @PriceRangePercent = (@SelectPrice - @MaxPrice)/@MaxPrice
GO
declare @PriceRangePercent Decimal(18,6)
Exec QueryPriceInList '10','100',@PriceRangePercent output
AS
Select @PriceRangePercent = (@SelectPrice - @MaxPrice)/@MaxPrice
GOdeclare @@PriceRangePercent Decimal(18,6)Exec QueryPriceInList 10,100,@@PriceRangePercent output
IF EXISTS( Select Name
From sysobjects
Where Name =N'QueryPriceInList'
And Type = 'P')
DROP PROCEDURE QueryPriceInList
GO
CREATE PROCEDURE QueryPriceInList @SelectPrice Decimal(18,6), @MaxPrice Decimal(18,6),@PriceRangePercent Decimal(18,6)OUTPUT
AS
Select @PriceRangePercent = (@SelectPrice - @MaxPrice)/@MaxPrice
GO
declare @PriceRangePercent decimal(18,6)
Exec QueryPriceInList '10','100',@PriceRangePercent output
select @PriceRangePercent
/*
--------------------
-.900000
*/
去掉后面的引号
IF EXISTS( Select Name
From sysobjects
Where Name =N'QueryPriceInList'
And Type = 'P')
DROP PROCEDURE QueryPriceInList
GO
CREATE PROCEDURE QueryPriceInList
@SelectPrice Decimal(18,6),
@MaxPrice Decimal(18,6),
@PriceRangePercent Decimal(18,6) OUTPUT
AS
Select @PriceRangePercent = (@SelectPrice - @MaxPrice)/@MaxPrice
GOdeclare @SelectPrice decimal(18,6),
@MaxPrice decimal(18,6),
@PriceRangePercent decimal(18,6)
set @SelectPrice = 10
set @MaxPrice = 100
Exec QueryPriceInList @SelectPrice,@MaxPrice,@PriceRangePercent output
print @PriceRangePercent