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 时出错。
请问该如何解决?

解决方案 »

  1.   

    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
      

  2.   

    Exec QueryPriceInList 10,100,'@PriceRangePercent'
      

  3.   

    @PriceRangePercent Decimal(18,6)
    而你传入了'@PriceRangePercent',肯定错了
    如果@PriceRangePercent是个decimal参数
    --Exec QueryPriceInList '10','100','@PriceRangePercent'
    ------------------------------------------------Exec QueryPriceInList '10','100',@PriceRangePercent
      

  4.   

    建议通过在函数中定义表变量,中转一下类型。在sql语句里面就不知道了。
      

  5.   

    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
      

  6.   

    CREATE PROCEDURE QueryPriceInList @SelectPrice Decimal(18,6), @MaxPrice Decimal(18,6),@@PriceRangePercent Decimal(18,6)OUTPUT
    AS
    Select @PriceRangePercent = (@SelectPrice - @MaxPrice)/@MaxPrice
    GOdeclare @@PriceRangePercent Decimal(18,6)Exec QueryPriceInList 10,100,@@PriceRangePercent output
      

  7.   

    --忘記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
    */
      

  8.   

    Exec QueryPriceInList '10','100',@PriceRangePercent
    去掉后面的引号
      

  9.   

    Exec QueryPriceInList '10','100',@PriceRangePercent去掉最后一个引号!
      

  10.   

    给你一个正确完整版:
    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