查询自定义函数关于decimal类型
CREATE function test2()
 Returns @temptable Table(RowID int identity(1,1) not null,aa decimal,bb decimal)
AS 
 begin
         
        insert  into @temptable select aa ,bb  from cc 
 return
 end 
 
上面的自定义含义查询语句如下 
select  aa,bb  from  test2()
为什么这里查出来的aa,bb变成整型了变成 0,3 ,而不是decimal类型,(直接select aa ,bb  from cc  ,cc表中 aa ,bb  是decimal类型 分别0.00,2.75)

解决方案 »

  1.   

    你应该指定 decimal 的精度和小数位数,比如 decimal(9, 2),表示总共有 9 位,其中小数占 2 位。
      

  2.   

    CREATE function test2() 
    Returns @temptable Table(RowID int identity(1,1) not null,aa decimal(10,5),bb decimal(10,5)) 
    AS 
    begin 
            
            insert  into @temptable select aa ,bb  from cc 
    return 
    end 
    改成想要的精度看看
      

  3.   

    decimal没有给小数位 -->decimal(8,2)
      

  4.   

    CREATE function test2()
    Returns @temptable Table(RowID int identity(1,1) not null,aa decimal(8,2),bb decimal(8,2))
    AS
    begin
           
            insert  into @temptable select aa ,bb  from cc
    return
    end 成交。