Stored Procedure: Reducing Table Data
Posted
by SumGuy
on Stack Overflow
See other posts from Stack Overflow
or by SumGuy
Published on 2010-05-26T15:25:40Z
Indexed on
2010/05/26
15:41 UTC
Read the original article
Hit count: 234
Hi Guys,
A simple question about Stored Procedures.
I have one stored procedure collecting a whole bunch of data in a table. I then call this procedure from within another stored procedure. I can copy the data into a new table created in the calling procedure but as far as I can see the tables have to be identical.
Is this right? Or is there a way to insert only the data I want?
For example....
I have one procedure which returns this:
SELECT @batch as Batch, @Count as Qty, pd.Location, cast(pd.GL as decimal(10,3)) as [Length], cast(pd.GW as decimal(10,3)) as Width, cast(pd.GT as decimal(10,3)) as Thickness FROM propertydata pd GROUP BY pd.Location, pd.GL, pd.GW, pd.GT
I then call this procedure but only want the following data:
DECLARE @BatchTable TABLE ( Batch varchar(50), [Length] decimal(10,3), Width decimal(10,3), Thickness decimal(10,3), )
INSERT @BatchTable (Batch, [Length], Width, Thickness) EXEC dbo.batch_drawings_NEW @batch
So in the second command I don't want the Qty and Location values.
However the code above keeps returning the error:
"Insert Error: Column name or number of supplied values does not match table"
© Stack Overflow or respective owner