In MS Access you can do the following using both tables and SELECT queries
FROM Product INNER JOIN outputQry ON Product.ProductId = outputQry.ProductId
Assuming Product is a table and outputQry a query, how to do the same in T-SQL ?
I wrote a function that returns a table, how do I execute it within another function/procedure so I can (for example) INNER JOIN the result with some tables?
My function looks like this
ALTER FUNCTION [dbo].[PreconfiguredConfigs_GetNoOfOutputs]()
RETURNS @outputTable TABLE
(
ProductId int,
NumberOfOutputs int
)
AS
BEGIN
DECLARE @table TABLE
(
ProductId int,
NumberOfOutputs int
)
INSERT INTO @table
SELECT Outputs.ProductId, Count(Outputs.ProductId) AS NumberOfOutputs
FROM [dbo.PreconfiguredConfigs].[Outputs]
GROUP BY Outputs.ProductId;
INSERT INTO @outputTable
SELECT ProductId, NumberOfOutputs FROM @table
RETURN
END
edit: one additional requirement would be that I can 'chain' the functions, so the results from one written above can be used in the another function (INNER JOINing it with other columns), and that function results could be used as well in another function (JOINing these as well).
Can it even be done or do I have to drastically change my designs? The requirements come from the way the database was designed in Access.
This poster suggested to put the SELECT query inside a table-value function, which I did, but I do not understand this line:
SELECT * INTO CustList FROM CustomersbyRegion(1)
what is CustList? Is it a table in the database that gets overwritten whenever the function gets called? I guess that would be a solution, because then I could INNER JOIN it all I want and avoid all the Invalid column name
errors I've been seeing when using variables and temporary tables (more on that in my comment to Rick S)