Click here to Skip to main content
15,886,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am getting the following error while I am trying to execute the following query..

'Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.'

SQL
DECLARE @UserId INT 
DECLARE @OriginatorId Varchar(16) 
SET @UserId=7516
SET @OriginatorId=33647


INSERT INTO dbo.tblAccount
( 
		UserID_Created , UserID_Assigned ,OriginatorID , OrigAccountID , AccountName , StatusTypeID ,DateCreated , AccountTypeID ,OnlineID , 
		IsLockedForOffline ,
		ConvertedByUserID , DateConvertedFromLead ,ExternalAccountID
)	
SELECT @UserId,@UserId,@OriginatorId,FileKey,'Account '+CAST(FileKey AS VARCHAR),-1,GETDATE(),972, -1,	0,	null,NULL,NULL
FROM dbo.ApplicantDetails
GROUP BY FileKey
having FileKey IN ('8','9')


Can anyone help?

Thanks
Nasif
Posted
Updated 30-May-13 16:52pm
v2
Comments
Prasaad SJ 30-May-13 22:21pm    
At which line number you are getting this error.
NASIFKHAN 31-May-13 0:31am    
Basically the error is in the query ...
SELECT @UserId,@UserId,@OriginatorId,FileKey,'Account '+CAST(FileKey AS VARCHAR),-1,GETDATE(),972, -1, 0, null,NULL,NULL
FROM dbo.ApplicantDetails
GROUP BY FileKey
having FileKey IN ('8','9')

I need to rewrite it ... but don't know how to do it..


If I ran the query separately, the query is ok

Thanks
Nasif
Arun Vasu 31-May-13 0:42am    
while running this query what will be the output?
SELECT @UserId,@UserId,@OriginatorId,FileKey,'Account '+CAST(FileKey AS VARCHAR),-1,GETDATE(),972, -1, 0, null,NULL,NULL
FROM dbo.ApplicantDetails
GROUP BY FileKey
having FileKey IN ('8','9')


pls show me..

write VALUES before select in your query
 
Share this answer
 
As a beginner every person lands up in getting this kind of error. Alternative is to re-write the SQL to suite the requirement. Using such sub query should be avoided since it may impact the performance in case of large data.
Alternative are
1) Iterate the cursor and insert one by one
2) User of Distinct clause of SQL
3) User Correlated Subquery in case you need to use operators like >, = etc.
4) Bulk SQL - Support by databases like Oracle

Regards,
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900