简体   繁体   中英

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=

I have 2 table called Prac1 and prac2 . Prac1 has trigger.When insertion happen in prac1 ,same entry goes in prac2 (trigger code).I have made one sp,in that selecting top 3 id from prac1 and inserting again into prac1 with it's value(other column).But only one row get added not 3.Query is:

Insert name,lname into prac1 where id in(select top3 id from prac1).

When I am removing trigger,my sp get executed and 3 entry get added into table.How to handle this situation?

prac1:Id,Name,Lname
prac2:Name,Lname

Are you sure your query is working? Because as already stated on a comment, the syntax is not valid. Take a look into MSDN for more information The correct syntax is:

INSERT [INTO] 
      table_name  [ ( column_list ) ] 
      { VALUES 
      ( { DEFAULT | NULL | expression } [ ,...n] ) 
| derived_table
       }

So your insert query should something like:

INSERT INTO prac1(name, lname) 
SELECT TOP 3 name, lname
  FROM prac1

Post your trigger code, the line you see inserted should be the first one that triggers the trigger. Nevertheless, the inserts could trigger it again. So maybe you will need to disable it and reenable it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM