Yes, a Multistatement TVF (as opposed to an Inline one like I had tried earlier, or even a View) seems to work.
So first this:
CREATE FUNCTION dbo.TestWrapper()
RETURNS @Temp TABLE (IntVal INT)
BEGIN
INSERT INTO @Temp (IntVal)
SELECT IntVal
FROM SQL#.Util_GenerateInts(1, 4, 1)
RETURN
END
and then this should work:
DECLARE @Table TABLE (IntVal INT NOT NULL)
IF (1 = 0)
BEGIN
INSERT INTO @Table (IntVal)
SELECT IntVal
FROM dbo.TestWrapper()
END
However, if this is called repeatedly or if the CLR function returns a lot of rows, doing a Multistatement TVF could be inefficient. In that case you would be left with the Stored Procedure option.
Hope that helps.
Take care,
Solomon...
SQL# — https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
Sql Quantum Lift — https://SqlQuantumLift.com/ ( company )
Sql Quantum Leap — https://SqlQuantumLeap.com/ ( blog )
Info sites — Collations • Module Signing • SQLCLR
Tricking the T-SQL compiler is a clever solution. Better, performance penalty is insignificant. Thanks a lot!
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply