Search code examples
sqlsql-server

SQL inline query insertinto


INSERT INTO ServiceID_302
 (Services)
 VALUES (
('Preliminaries'),
 ('Demolition'),
 ('DRAINAGE_AND_REFUSE_DISPOSAL'),
 ('GAS_DISTRIBUTION-COMPRESSED_AIR'),
 ('SPACE_COOLING-CHILLED_WATER'),
 ('SPACE_HEATING-LOW_PRESSURE_HOT_WATER'),
 ('VENTILATION_&_AIR_CONDITIONING'),
 ('OTHER_MECHANICAL_SERVICES'),
 ('Sprinkler'),
 ('Dayworks'),
 ('COMMERCIAL_DISCOUNT'),
 ('VARIATIONS')
 );

I am trying to insert this using inline query it throws an error :

There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.'

I have this structure where id is primary key also its a identity column

     SELECT [Id]
          ,[Services]
      FROM [CostManagement].[dbo].[ServiceID_302]

Solution

  • Brackets are more than needed. Remove the ones that wraps all Values

    INSERT INTO ServiceID_302
     (Services)
     VALUES 
     ('Preliminaries'),
     ('Demolition'),
     ('DRAINAGE_AND_REFUSE_DISPOSAL'),
     ('GAS_DISTRIBUTION-COMPRESSED_AIR'),
     ('SPACE_COOLING-CHILLED_WATER'),
     ('SPACE_HEATING-LOW_PRESSURE_HOT_WATER'),
     ('VENTILATION_&_AIR_CONDITIONING'),
     ('OTHER_MECHANICAL_SERVICES'),
     ('Sprinkler'),
     ('Dayworks'),
     ('COMMERCIAL_DISCOUNT'),
     ('VARIATIONS')