insert with select on sql server

1

I have the following code where I create a table and I want to insert information that came out of a query:

CREATE TABLE AR_TABLA_REORI (TER VARCHAR(50),REG VARCHAR(50),ORIGEN INT, CLIENTES INT, TOTAL INT,SUCORIGEN INT)

INSERT INTO AR_TABLA_REORI VALUES (TER ,REG ,ORIGEN ,CLIENTES )
SELECT TERL,REG,ORIGEN, COUNT(*) AS SUCORIGEN 
FROM CLIENTES_TBL

Data types in table CLIENTES_TBL

TER nvarchar(510)
REG nvarchar(510)
ORIGEN INT
CLIENTES INT

I have the following error:

  

The name "TER" is not permitted in this context. Valid expressions are   constants, constant expressions, and (in some contexts) variables.   Column names are not permitted.

    
asked by ARR 16.08.2018 в 23:48
source

1 answer

1

Values is over in the statement, insert select

INSERT INTO AR_TABLA_REORI (TER ,REG ,ORIGEN ,CLIENTES )
SELECT TERL,REG,ORIGEN, COUNT(*) 
FROM CLIENTES_TBL
    
answered by 17.08.2018 / 00:11
source