Assign a Select to a Table in SQL Function

1

In a function in SQL Server there is some way to create a table and assign it the value of a query, something like

CREATE TABLE AuxAlumnos
(
   Id       int,
   Nombre   varchar (10),
   Apellido varchar(10)
);

And to that table assign the value of a SELECT * FROM Alumnos

    
asked by Alejandro Ricotti 07.04.2017 в 16:36
source

3 answers

2

If you can or can do with temporary tables or concrete tables you will have something similar to this:

Concrete table:

CREATE PROCEDURE MI_PROCEDIMIENTO
AS

    CREATE TABLE #AuxAlumnos
    (
       Id       int,
       Nombre   varchar (10),
       Apellido varchar(10)
    );

    INSERT  INTO #AuxAlumnos (ID,NOMBRE,APELLIDO) 
    SELECT  ID,NOMBRE,APELLIDO
    FROM    Alumnos

Temporary Table:

CREATE PROCEDURE MI_PROCEDIMIENTO
AS

    DECLARE @AuxAlumnos TABLE
    (
          Id       int,
          Nombre   varchar (10),
          Apellido varchar(10)
    )

    INSERT  INTO @AuxAlumnos (ID,NOMBRE,APELLIDO)
    SELECT  ID,NOMBRE,APELLIDO
    FROM    Alumnos

then you just have to select the table you just created.

I hope it's your help

Greetings

    
answered by 07.04.2017 / 16:46
source
2

You can do the following:

SELECT CAMPO1, CAMPO2, CAMPO3 INTO NUEVATABLA FROM VIEJATABLA
    
answered by 07.04.2017 в 16:42
0

What exactly do you want to do? The question is not clear.

Maybe you want to do something like:

  

SELECT * FROM fuMiFunction ('x')

If so, if it can be done.

    
answered by 07.04.2017 в 18:33