I need help with a procedure...
The problem is that i need use a select but the table refered is parameter (variable, etc), and i don´t know how i do this.
Example:
CREATE PROCEDURE ProcedureName @idvariable int,@NombreTabla varchar(20)
AS
...
DECLARE @FechaSalida datetime, @FechaEntrada datetime, @otravariable int
SELECT @FechaSalida = FechaHoraSalida, @FechaEntrada = FechaHoraEntrada FROM @NombreTabla
where Idvariable = @idvariable
...etc
There is the problem how can i use the name of the table (@NombreTabla) as parameter?
I try anothers forms but nothing works.
this works:
EXEC("SELECT FechaHoraSalida, FechaHoraEntrada FROM "+ @NombreTabla + " where 2 = Idvariable" )
but...need return and use other variable
tnx...
The problem is that i need use a select but the table refered is parameter (variable, etc), and i don´t know how i do this.
Example:
CREATE PROCEDURE ProcedureName @idvariable int,@NombreTabla varchar(20)
AS
...
DECLARE @FechaSalida datetime, @FechaEntrada datetime, @otravariable int
SELECT @FechaSalida = FechaHoraSalida, @FechaEntrada = FechaHoraEntrada FROM @NombreTabla
where Idvariable = @idvariable
...etc
There is the problem how can i use the name of the table (@NombreTabla) as parameter?
I try anothers forms but nothing works.
this works:
EXEC("SELECT FechaHoraSalida, FechaHoraEntrada FROM "+ @NombreTabla + " where 2 = Idvariable" )
but...need return and use other variable
tnx...