Home Forums SQL Server 2008 SQL Server 2008 - General On the same server, can you use a TABLE-valued user-defined function from another database? RE: On the same server, can you use a TABLE-valued user-defined function from another database?

  • Chris Harshman - Wednesday, January 3, 2018 10:49 AM

    it looks like you're trying to reference the table valued function as you would a scalar function, by putting it in the SELECT clause.  It would work better to APPLY to it in your FROM clause like:
    SELECT InvWarehouse.StockCode, InvWarehouse.Warehouse, InvWarehouse.YtdQtySold, InvWarehouse.PrevYearQtySold, InvWarehouse.UnitCost, InvMaster.MinPricePct,
       InvPrice.PriceCode, InvPrice.SellingPrice, InvMaster.ProductClass, InvMaster.PriceCategory, InvMaster.PriceMethod, lrd.columnname
    FROM InvMaster
    INNER JOIN InvWarehouse ON InvMaster.StockCode = InvWarehouse.StockCode AND InvMaster.WarehouseToUse = InvWarehouse.Warehouse
    INNER JOIN InvPrice ON InvMaster.StockCode = InvPrice.StockCode AND InvMaster.StockCode = InvPrice.StockCode
    CROSS APPLY [W_SE-MFG].[dbo].[LastRecDate_tvf](InvMaster.StockCode, InvWarehouse.Warehouse, 'K') lrd

    Yeah I noticed it and that was my main error.  Thanks