如果表为空,如何设置属性表?
如果 #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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法检查
#tableTemporal
是否为 null,因为它永远不会为 null。您可能想在执行paBltMarcarErroresBoleta
后检查是否有行插入到 #tableTemporal 中。如果我理解正确,我认为您可以在
exec dbo.paBltMarcarErroresBoleta @boletaActual
之后执行类似的操作:在
exec dbo.paBltMarcarErroresBoleta @boletaActual
之后但是您可以更好地执行此操作一个简单的 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 execpaBltMarcarErroresBoleta
.If I understood correctly, I think you could do after
exec dbo.paBltMarcarErroresBoleta @boletaActual
something like:And after
exec dbo.paBltMarcarErroresBoleta @boletaActual
But you can probably execute this better with a simple while loop instead of the cursor.