Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Below is a complete, working (for SQL 2005) example of what you're talking about.</p> <p>The bad news is, I don't believe there is any way to do what you're trying to do. Sorry. It looks like the SP writer made it impossible.</p> <p>If someone comes up with some creative way to make this work, great!</p> <pre><code>IF OBJECT_ID('tempdb..#tempTable') IS NOT NULL DROP TABLE #tempTable GO IF EXISTS (SELECT * FROM sys.procedures WHERE name = 'sproc_Select_Stuff_By_DateCreated') DROP PROCEDURE dbo.sproc_Select_Stuff_By_DateCreated GO CREATE PROCEDURE dbo.sproc_Select_Stuff_By_DateCreated @Date1 datetime, @Date2 datetime AS BEGIN ;WITH t AS ( SELECT 1 AS TempId, 'Column1-val1' AS Column1, 'Column2-val1' AS Column2, '2009-01-01 10:00:00' AS DateCreated UNION ALL SELECT 2, 'Column1-val2', 'Column2-val2', '2009-01-01 11:00:00' ) SELECT TempId, Column1, Column2, DateCreated FROM t -- ReallyHugeMessOfJoinsAndCalculatedColumns WHERE DateCreated between @Date1 and @Date2 SELECT @Date1 as Date1, @Date2 as Date2 END GO create table #tempTable ( TempId int primary key, Column1 varchar(100), Column2 varchar(100), DateCreated datetime ) insert into #tempTable (TempId, Column1, Column2, DateCreated) exec dbo.sproc_Select_Stuff_By_DateCreated @Date1 = '1/1/2009', @Date2 = '1/2/2009' --SELECT * FROM #tempTable ---------------------------------------- Msg 213, Level 16, State 7, Procedure sproc_Select_Stuff_By_DateCreated, Line 26 Insert Error: Column name or number of supplied values does not match table definition. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload