Just encapsulate the SELECT for the INSERT in an EXEC so that it is not a parse-time issue. For example:
DECLARE @Table TABLE (IntVal INT NOT NULL)
IF (1 = 0)
BEGIN
INSERT INTO @Table (IntVal)
EXEC('
SELECT IntVal
FROM SQL#.Util_GenerateInts(1, 4, 1)
')
END
What is inside of the EXEC is not parsed unless the EXEC itself is run. I get around many parse-time issues in this manner :-).
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