[英]Return Table from stored procedure
I have this stored procedure that call other second stored procedure which returns a table with 5 columns. 我有这个存储过程,它调用其他第二个存储过程,该存储过程返回一个包含5列的表。 I insert the results into the temporary table in the first stored procedure.
我将结果插入第一个存储过程中的临时表。 The idea is to show this table in a Crystal Report, so I need this stored procedure to return the temporary table.
我的想法是在Crystal Report中显示此表,因此我需要此存储过程来返回临时表。
How can I make it to return the table with the 5 columns and the values?? 如何使它返回包含5列和值的表?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[paBltBuscarBoletasASA] @id_Asa int
-- Add the parameters for the stored procedure here
AS
DECLARE @Query int
CREATE TABLE #tablaTemporal (Numero_Pregunta varchar, Numero_Boleta int, Cultivo varchar, Numero_Siembra int, Detalle_Error varchar)
DECLARE miCursor CURSOR FOR
SELECT
localizacion.c_Fk_IdBoleta
FROM
Blt_Boleta as boleta, Fnc_Localizacion as localizacion
WHERE
boleta.c_Pk_IdBoleta = localizacion.c_Fk_IdBoleta AND
localizacion.si_CodAsa = @id_Asa
OPEN miCursor
FETCH NEXT FROM miCursor INTO @Query
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO #tablaTemporal(Numero_Pregunta, Numero_Boleta, Cultivo, Numero_Siembra, Detalle_Error) exec dbo.paBltMarcarErroresBoleta @Query
FETCH NEXT FROM miCursor INTO @Query
END
CLOSE miCursor
DEALLOCATE miCursor
Well the most obvious solution is to place at the bottom of the stored proc: 那么最明显的解决方案是放在存储过程的底部:
SELECT Numero_Pregunta, Numero_Boleta, Cultivo, Numero_Siembra, Detalle_Error
FROM #tablaTemporal
This will return the data to the stored proc caller. 这将把数据返回给存储的proc调用者。
Why does it have to be temporary? 为什么它必须是暂时的?
Can the table data simply be refreshed each time? 表格数据每次都可以简单刷新吗? Then you don't run into the issue of the temp table being destroyed each time it falls out of scope/context.
然后,每次超出范围/上下文时,都不会遇到临时表被销毁的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.