1

What is the problem with this query?

insert into fatora (item_id, item_name, items_number, item_dis, item_sell, fatora_type)
values ( (Select item_id, item_name, item_number, item_dis, item_dis from helper), 1)

I get this error:

Msg 116, Level 16, State 1, Line 2 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Msg 109, Level 15, State 1, Line 1 There are more 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
fahd hakem
  • 11
  • 1
  • 1
    The syntax is `insert (a, b, c, ...) select a, b, c, ... from ...` – SMor Feb 19 '22 at 03:20
  • I want to add value with select – fahd hakem Feb 19 '22 at 03:53
  • Don't use BOTH a `select` and `values` clause. Only the `select` https://en.wikipedia.org/wiki/Insert_(SQL)#Copying_rows_from_other_tables – SOS Feb 19 '22 at 04:48
  • 1
    Side note: After selecting PeterJ's answer from below, double check the mapping. You are pulling item_dis twice. – T N Feb 19 '22 at 05:35

2 Answers2

6

In an SQL select query you can use literal values instead of column names. So in your case when you want each new row to have fatora_type set to 1 you can use the following:

insert into fatora
  (item_id, item_name, items_number, item_dis, item_sell, fatora_type)
  Select item_id, item_name, item_number, item_dis, item_dis, 1 from helpe
PeterJ
  • 3,705
  • 28
  • 51
  • 71
-1

You are missing a value for the fatora_type column in the select clause.

Mike Wodarczyk
  • 1,247
  • 13
  • 18