定义一个表值函数
fn_GetMoneysfor_sp_SalesRegistration(int ID)此函数只返回一行数据如果使用  select fname from fn_GetMoneysfor_sp_SalesRegistration(1) 可以返回正确数据
如果在查询语句中调用却出现问题。如下:消息 102,级别 15,状态 1,第 18 行
'.' 附近有语法错误。
select  fname=(select fname fn_GetMoneysfor_sp_SalesRegistration(t.id))  from table as t函数前面无论加不加所有者都是一样的错误。
是不是不能这样调用呢!请问改如何调用才不会出现问题?谢谢!

解决方案 »

  1.   

    select fname from dbo.fn_GetMoneysfor_sp_SalesRegistration(1)
      

  2.   

    select fname=(select fname from  fn_GetMoneysfor_sp_SalesRegistration(t.id)) from table as t
      

  3.   


    你好!这样调用是没有问题的,不加所有者dbo也没有问题!但是使用下面的查询就会有问题!elect fname=(select fname fn_GetMoneysfor_sp_SalesRegistration(t.id)) from table as t
      

  4.   


    写这个是没有问题的!加不加所有者dbo都一样!但是使用下面查询就出问题。select fname=(select fname fn_GetMoneysfor_sp_SalesRegistration(t.id)) from table as t
      

  5.   


    你好  感谢你的回复!加上 from也是存在这个问题!
      

  6.   

    select fname=(select top 1 fname fn_GetMoneysfor_sp_SalesRegistration(t.id)) from table as t
      

  7.   

    加上from也不行的话,是不是考虑你其他语句用到别名的时候'.'附近有语法错误
      

  8.   


    CREATE TABLE [dbo].[Tmp_Tbl](
    [TypeID] [smallint] NOT NULL,
    [TypeName] [nvarchar](128) NULL,
    [Caption] [nvarchar](128) NULL
    ) ON [PRIMARY]
    IF OBJECT_ID (N'fn_test') IS NOT NULL
        DROP FUNCTION fn_test
    GOCREATE FUNCTION fn_test (@ID Int)
    RETURNS TABLE
    AS RETURN
    (
    Select TypeID, TypeName, Caption From Sy_Datatypes Where TypeID=@ID
    )
    GOSelect *, (Select TypeName from dbo.fn_test(A.TypeID)) TFld from SY_DataTypes a
      

  9.   


    你好  我这还是出现了  这个错误 '.' 附近有语法错误。是不是和SQl版本有关!我的版本为  MSSQL 2005
      

  10.   

    select fname=(select fname from fn_GetMoneysfor_sp_SalesRegistration(t.id)) from table as t少了个from,如果加了from还是报错,那错误可能是由于t.id引起
      

  11.   


    from 加了还是错误!请问不能使用这种方式调用函数吗?
      

  12.   

    是不是兼容模式出问题 EXEC sp_dbcmptlevel databasename, 90;