This one's been bugging me all night.
OK, at present this is what I do.
I have a stored procedure (usp_ReportMaster) which returns the result of a dynamic SQL query like this:
SELECT Improvement.* FROM ..........
I then have many other stored procedures that run the above stored proc first and then run a second filter on the result (like this)
CREATE TABLE #ReportMaster (
[ImprovementID] [bigint] NOT NULL,
......
)
INSERT INTO #ReportMaster EXEC usp_ReportMaster @Filters, @Company, @User
SELECT ... FROM #ReportMaster WHERE .......
-----------------------
All well and good, but everytime the structure of the Improvement table changes, I have to change ALL the stored procedures' temp tables to reflect this - BIG HASSLE as there are loads of them.
I have been experimenting with SELECT INTO and OPENROWSET. I pretty much have the OPENROWSET method working (with static params at present, need to make them dynamic), but that introduces other aspects which may have to be changed every now and then, so isn't really satisfactory.
Therefore I have been looking at SELECT INTO to get the structure for me with the following code:
SELECT * INTO #ReportMaster FROM Improvement WHERE 0 = 1
INSERT INTO #ReportMaster EXEC usp_ReportMaster @Filters, @Company, @User
However, I get this error:
Insert Error: Column name or number of supplied values does not match table definition.
Which so doesn't make sense as the SELECT INTO query and the usp_ReportMaster both return the entire data structure (only) of the Improvement table and are identical as far as I can see (I have compared the resulting structure output from each statement).
I have also tried using table variables and UDFs and there is always some restriction that stops me doing what I want.
If anyone has any bright ideas, I will be very grateful
OK, at present this is what I do.
I have a stored procedure (usp_ReportMaster) which returns the result of a dynamic SQL query like this:
SELECT Improvement.* FROM ..........
I then have many other stored procedures that run the above stored proc first and then run a second filter on the result (like this)
CREATE TABLE #ReportMaster (
[ImprovementID] [bigint] NOT NULL,
......
)
INSERT INTO #ReportMaster EXEC usp_ReportMaster @Filters, @Company, @User
SELECT ... FROM #ReportMaster WHERE .......
-----------------------
All well and good, but everytime the structure of the Improvement table changes, I have to change ALL the stored procedures' temp tables to reflect this - BIG HASSLE as there are loads of them.
I have been experimenting with SELECT INTO and OPENROWSET. I pretty much have the OPENROWSET method working (with static params at present, need to make them dynamic), but that introduces other aspects which may have to be changed every now and then, so isn't really satisfactory.
Therefore I have been looking at SELECT INTO to get the structure for me with the following code:
SELECT * INTO #ReportMaster FROM Improvement WHERE 0 = 1
INSERT INTO #ReportMaster EXEC usp_ReportMaster @Filters, @Company, @User
However, I get this error:
Insert Error: Column name or number of supplied values does not match table definition.
Which so doesn't make sense as the SELECT INTO query and the usp_ReportMaster both return the entire data structure (only) of the Improvement table and are identical as far as I can see (I have compared the resulting structure output from each statement).
I have also tried using table variables and UDFs and there is always some restriction that stops me doing what I want.
If anyone has any bright ideas, I will be very grateful