StatsViaCsh
StatsViaCsh

Reputation: 2640

SQL server Can I pass the results of a table- valued function to a stored procedure?

I have a conceptual way I'd like to code a set of related functions and stored procedures. I'm hoping to get a little feedback on whether or not that way is doable.

In a stored procedure, I'd like to assign the values of a table-valued function to a temporary table, then pass that table to another stored procedure...

Can I do this without creating table types?

Upvotes: 0

Views: 812

Answers (1)

Aaron Bertrand
Aaron Bertrand

Reputation: 280429

A quick sample of the #temp table solution:

CREATE PROCEDURE dbo.B
AS
BEGIN
    SET NOCOUNT ON;

    SELECT * FROM #foo;
END
GO

CREATE PROCEDURE dbo.A
AS
BEGIN
    SET NOCOUNT ON;

    SELECT TOP 1 * INTO #foo FROM sys.objects;

    EXEC dbo.B;

    DROP TABLE #foo;
END
GO

EXEC dbo.A;

DROP PROCEDURE dbo.A, dbo.B;

Upvotes: 1

Related Questions