Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
My Subquery will return multiple values.NameABCDEFI need to insert this into another table as separate rows, likeID Name 1 ABC 2 DEF I tried to give the subquery likeINSERT into Table(col1 INT,col2 VARCHAR)VALUES(ID,(Subquery returning ABC,DEF))But it will give errror indicating subquery returns multiple values.Thanks in advance.
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-10-22 : 07:20:47
You have to change your query so that it does not return multiple values. Where does ID come from? May be you can change your subquery to include ID as well and use it like this:
INSERT INTO [Table](col1, col2)SELECT ID,NameFROM SomeQuery
The other option is to insert only one value, but I don't think that is what you want:
INSERT into Table(col1 INT,col2 VARCHAR)VALUES(ID,(SELECT TOP 1 ABC,DEF))
chaaru_akilan
Starting Member
16 Posts
Posted - 2012-10-22 : 08:53:40
I changed my Subquery and did modifications similar to the first query of urs and it worked. Thank you