INNER JOIN with Table-Valued Function not working

后端 未结 4 1692
执笔经年
执笔经年 2020-12-06 04:19

I have a table valued function that returns a table. When I try to JOIN the table-valued function with another table I don\'t get any results, but when I copy t

相关标签:
4条回答
  • 2020-12-06 04:32

    If we made some assumptions that params of table valued functions are not dependent on myTable columns dynamically this will work.

       SELECT *
        FROM myTable 
        INNER JOIN
    
        (SELECT * from fn_function(@para1, @para2 etc))
     ON ...
    

    but if the params are dependent on myTable it will not work

    0 讨论(0)
  • 2020-12-06 04:40

    I think this should work

      Select * 
        From Animals 
        Join dbo.AnimalsTypesIds(900343) 
          As AnimalsTypes
          On AnimalsTypes.TypeId = Animals.TypeId
    

    In table valued function the return table should have TypeId so that join works on that clause

    0 讨论(0)
  • 2020-12-06 04:42

    Your "ON" clause of the join is most likely incorrect. Perhaps a small typo like

    JOIN x ON oID = odID

    instead of

    JOIN x ON oID = oID

    0 讨论(0)
  • 2020-12-06 04:47

    With the table valued function you generally use Cross Apply.

    Select *
    From myTable m
    CROSS APPLY fn_function(m.field1, m.field2)
    
    0 讨论(0)
提交回复
热议问题