
Ingresar un SELECT en una variable en SQL SERVER 2022
Publicado por Sebastian (1 intervención) el 05/06/2024 18:45:39
Buenas tardes, estoy queríendo realizar una consulta SQL la cual quiero guardar ese registro en una variable @. Les paso el ejemplo:
CREATE OR ALTER PROCEDURE BajaCliente
DECLARE @MyTableVar TABLE (a INT);
DECLARE @dniCliente int
AS
@MyTableVar = select distinct(1)
from [orden].dbo.orden o
inner join [orden].dbo.cliente c on (o.dni_cliente = c.dni)
where c.dni = @dniCliente
Error que me emite:
Msg 156, Level 15, State 1, Procedure BajaCliente, Line 2 [Batch Start Line 43]
Incorrect syntax near the keyword 'DECLARE'.
Msg 156, Level 15, State 1, Procedure BajaCliente, Line 4 [Batch Start Line 43]
Incorrect syntax near the keyword 'AS'.
Msg 137, Level 15, State 2, Procedure BajaCliente, Line 9 [Batch Start Line 43]
Must declare the scalar variable "@dniCliente".
Completion time: 2024-06-05T13:41:45.7852178-03:00
Muchas Gracias

CREATE OR ALTER PROCEDURE BajaCliente
DECLARE @MyTableVar TABLE (a INT);
DECLARE @dniCliente int
AS
@MyTableVar = select distinct(1)
from [orden].dbo.orden o
inner join [orden].dbo.cliente c on (o.dni_cliente = c.dni)
where c.dni = @dniCliente
Error que me emite:
Msg 156, Level 15, State 1, Procedure BajaCliente, Line 2 [Batch Start Line 43]
Incorrect syntax near the keyword 'DECLARE'.
Msg 156, Level 15, State 1, Procedure BajaCliente, Line 4 [Batch Start Line 43]
Incorrect syntax near the keyword 'AS'.
Msg 137, Level 15, State 2, Procedure BajaCliente, Line 9 [Batch Start Line 43]
Must declare the scalar variable "@dniCliente".
Completion time: 2024-06-05T13:41:45.7852178-03:00
Muchas Gracias

Valora esta pregunta


0