如果表为空,如何设置属性表?

发布于 2024-12-12 05:16:25 字数 1220 浏览 0 评论 0原文

如果 #tablaTemporal = null,我需要设置表 Blt_Boleta.ti_Pk_IdEstadoRevision = 3 的属性。我正在考虑在 Insert 和 FETCH NEXT FROM miCursor INTO @boletaActual 之间进行此操作。也许是伯爵或类似的东西......

那么我该怎么做呢?

ALTER PROCEDURE [dbo].[paBltBuscarBoletasASA] @id_Asa int  
      -- Add the parameters for the stored procedure here
AS
DECLARE @boletaActual int
CREATE TABLE #tablaTemporal 
(
Numero_Pregunta varchar(250), 
Numero_Boleta char(8), 
Cultivo varchar(250), 
Numero_Siembra int, 
Detalle_Error varchar(250)
)
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 @boletaActual

WHILE @@FETCH_STATUS = 0

BEGIN 
INSERT INTO #tablaTemporal
(Numero_Pregunta, Numero_Boleta, Cultivo, Numero_Siembra, Detalle_Error)  
exec dbo.paBltMarcarErroresBoleta @boletaActual

FETCH NEXT FROM miCursor INTO @boletaActual
END

CLOSE miCursor
DEALLOCATE miCursor
SELECT * FROM #tablaTemporal 

I need SET a property of a table Blt_Boleta.ti_Pk_IdEstadoRevision = 3, if #tablaTemporal = null. I was thinking make this between the Insert and FETCH NEXT FROM miCursor INTO @boletaActual. Maybe with a Count or somethig like this...

So how can I do this?

ALTER PROCEDURE [dbo].[paBltBuscarBoletasASA] @id_Asa int  
      -- Add the parameters for the stored procedure here
AS
DECLARE @boletaActual int
CREATE TABLE #tablaTemporal 
(
Numero_Pregunta varchar(250), 
Numero_Boleta char(8), 
Cultivo varchar(250), 
Numero_Siembra int, 
Detalle_Error varchar(250)
)
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 @boletaActual

WHILE @@FETCH_STATUS = 0

BEGIN 
INSERT INTO #tablaTemporal
(Numero_Pregunta, Numero_Boleta, Cultivo, Numero_Siembra, Detalle_Error)  
exec dbo.paBltMarcarErroresBoleta @boletaActual

FETCH NEXT FROM miCursor INTO @boletaActual
END

CLOSE miCursor
DEALLOCATE miCursor
SELECT * FROM #tablaTemporal 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2024-12-19 05:16:25

您无法检查 #tableTemporal 是否为 null,因为它永远不会为 null。您可能想在执行 paBltMarcarErroresBoleta 后检查是否有行插入到 #tableTemporal 中。

如果我理解正确,我认为您可以在 exec dbo.paBltMarcarErroresBoleta @boletaActual 之后执行类似的操作:

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
FOR UPDATE OF Blt_Boleta.ti_Pk_IdEstadoRevision 

exec dbo.paBltMarcarErroresBoleta @boletaActual 之后

if not exists(select 1 from #tableTemporal)
 update Blt_Boleta
 set Blt_Boleta.ti_Pk_IdEstadoRevision=3 
 where current of miCursor

但是您可以更好地执行此操作一个简单的 while 循环而不是光标。

You can't check whether #tableTemporal is null because it will never be. You probably meant to check if there are rows inserted into #tableTemporal after you exec paBltMarcarErroresBoleta.

If I understood correctly, I think you could do after exec dbo.paBltMarcarErroresBoleta @boletaActual something like:

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
FOR UPDATE OF Blt_Boleta.ti_Pk_IdEstadoRevision 

And after exec dbo.paBltMarcarErroresBoleta @boletaActual

if not exists(select 1 from #tableTemporal)
 update Blt_Boleta
 set Blt_Boleta.ti_Pk_IdEstadoRevision=3 
 where current of miCursor

But you can probably execute this better with a simple while loop instead of the cursor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文