SQLServerCentral.com / SQL Server 2008 / SQL Server Newbies / Need Help with the Error 'Subquery returned more than 1 value'. / Latest PostsInstantForum.NET v99.99.99SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comFri, 09 Dec 2016 10:51:29 GMT20RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]nitha jen (6/12/2013)[/b][hr]can anyone help me? i am new to db....CREATE proc [dbo].[student_marks] @roll_no varchar(20) AS BEGIN CREATE TABLE #temp ( semester INT, marks INT ) INSERT INTO #temp ( semester, marks ) SELECT semester, ( SELECT SUM ( marks )/count(noof_sub) FROM student_details sd INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no WHERE sd.roll_no = @roll_no AND ri.semester = sm.sem_attended group by semester ) marks FROM student_details sd INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no WHERE sm.roll_no=@roll_no group by semesterSELECT *FROM #tempendthe problem is when i execute the query it returns "subquery returned more than 1 value' error".because of that subquery contains 3 semesters and marks.when i remove the group by function in subquery it returns the same value for 3 rows.but i need the result like semester marks 1 82 2 75 3 60what should i do to overcome this problem????thanks in advance :-):-)[/quote]Hi nitha, Welcome to SSC......a few things:1. Check the link in my signature to know how to post in forums. 2. Please don't hijack threads. Its already a 5 page thread and your question would get lost. 3. For fast and better solutions please post a new thread. Please post DDL and sample data as shown in the link in my signature. Help us help you. Hope you have a good time on SSC. :-)Wed, 12 Jun 2013 22:58:46 GMTvinu512RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]nitha jen (6/12/2013)[/b][hr]i don't understand,what you mean by sample data???[/quote]Sample data as outlined by reading the article found at the first link in my signature. Additionally you really should start your own thread for your question instead of jumping into somebody else's.Wed, 12 Jun 2013 07:16:43 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxi don't understand,what you mean by sample data???Wed, 12 Jun 2013 04:43:03 GMTneethu payalRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxAs Grass was told - we really need to see the sample data you are running this query against in order to make any meaningful suggestions.Wed, 12 Jun 2013 04:37:31 GMTStuart DaviesRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxcan anyone help me? i am new to db....CREATE proc [dbo].[student_marks] @roll_no varchar(20) AS BEGIN CREATE TABLE #temp ( semester INT, marks INT ) INSERT INTO #temp ( semester, marks ) SELECT semester, ( SELECT SUM ( marks )/count(noof_sub) FROM student_details sd INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no WHERE sd.roll_no = @roll_no AND ri.semester = sm.sem_attended group by semester ) marks FROM student_details sd INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no WHERE sm.roll_no=@roll_no group by semesterSELECT *FROM #tempendthe problem is when i execute the query it returns "subquery returned more than 1 value' error".because of that subquery contains 3 semesters and marks.when i remove the group by function in subquery it returns the same value for 3 rows.but i need the result like semester marks 1 82 2 75 3 60what should i do to overcome this problem????thanks in advance :-):-)Wed, 12 Jun 2013 04:07:57 GMTneethu payalRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxDistinct does not work but Top 1 works. I only change TOP 1 in the first 2 SET statements and it works, third and fourth statements i didn't change anything.thanks.Mon, 16 Apr 2012 07:35:46 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]Grass (4/15/2012)[/b][hr]I tried using before but didn't work.can u tell me how to use the distinct to replace SET statement.what fields needs to be distinct?thanks.[/quote]Try these for Distinct:SET @Project_ID = (SELECT Distinct project_id FROM int_aux_project WHERE [/img]project_cd = @Matter_ID)SET @Project_Desc = (SELECT Distinct project_nm FROM int_aux_project WHERE project_cd = @Matter_ID)SET @Listing_ID = (SELECT Distinct listing_id FROM int_aux_lst_custom WHERE string_value = @Billing_ID AND LST_CUSTOM_DEF_ID = '-10017')SET @User_ID= (SELECT Distinct user_id FROM int_user WHERE listing_id = @Listing_ID)If Distinct doesn't work, try these for Select 1:SET @Project_ID = (SELECT Top 1 project_id FROM int_aux_project WHERE [/img]project_cd = @Matter_ID)SET @Project_Desc = (SELECT Top 1 project_nm FROM int_aux_project WHERE project_cd = @Matter_ID)SET @Listing_ID = (SELECT Top 1 listing_id FROM int_aux_lst_custom WHERE string_value = @Billing_ID AND LST_CUSTOM_DEF_ID = '-10017')SET @User_ID= (SELECT Top 1 user_id FROM int_user WHERE listing_id = @Listing_ID)Mon, 16 Apr 2012 05:14:16 GMTvinu512RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxI tried using before but didn't work.can u tell me how to use the distinct to replace SET statement.what fields needs to be distinct?thanks.Sun, 15 Apr 2012 22:27:05 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]Grass (4/14/2012)[/b][hr]I think I actually found out which part of the code is giving the error. It is on the first two SET statements when I pass the three variables @Project_Id, @Matter_Id, and Project_Desc.Do you think I can rewrite that section of SET statements then it might work?Thanks.[/quote]Yes. Try using Select Distinct or Select 1 in those SET statements.Sun, 15 Apr 2012 22:08:04 GMTvinu512RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxI think I actually found out which part of the code is giving the error. It is on the first two SET statements when I pass the three variables @Project_Id, @Matter_Id, and Project_Desc.Do you think I can rewrite that section of SET statements then it might work?Thanks.Sat, 14 Apr 2012 14:18:05 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]Grass (4/13/2012)[/b][hr]The code I posted in my first post is in SQL Exexute Task from a SSIS package.[/quote]Fine, I got the code. Now, please post the correct DDL and some readily usable sample data against which I can check what is wrong with your code.Do what Lynn said in his last post. As soon as it is done we can start looking for what's wrong with the code.Fri, 13 Apr 2012 22:44:28 GMTvinu512RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxThe code I posted in my first post is in SQL Exexute Task from a SSIS package.Fri, 13 Apr 2012 07:25:36 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxGrass, you need to do a few things right so that we know what the problem is and can head into the right direction.1. Do what Lynn said in his last reply.2. What does the Execute Process task do??....What task is it executing?3. Can you tell us clearly which part is causing the error?....The code you posted or the SSIS package?We won't be able to move forward without the DDL and the sample data.Fri, 13 Apr 2012 02:34:54 GMTvinu512RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]Grass (4/12/2012)[/b][hr]vinu:I tried using select 1 and it still gives me error.but i haven't try distinct yet.if i use distinct what fields do i use from the table? I mean what the statement would be (select distinct (which column names comes here) from table name.Also, you mentioned that my ddl and data is not right. the create table script is right and the data i got from those table i created. the data that are in the select statements are shown in the table but it is not all the data. there are alot of rows so i just got few of it. please let me know what can be done.thanks.[/quote]Best thing you could do is create an empty database, call it sandbox or playpen, copy and paste your code from the forum to a query window and run it in the newly created empty database. If anything fails, fix it, drop everything from the database and rerun the script again. Repeat this process until your scripts run without errors. Then repost the corrected scripts.Thu, 12 Apr 2012 23:34:20 GMTLynn PettisRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxvinu:I tried using select 1 and it still gives me error.but i haven't try distinct yet.if i use distinct what fields do i use from the table? I mean what the statement would be (select distinct (which column names comes here) from table name.Also, you mentioned that my ddl and data is not right. the create table script is right and the data i got from those table i created. the data that are in the select statements are shown in the table but it is not all the data. there are alot of rows so i just got few of it. please let me know what can be done.I forgot to mention that the error occurred in the SSIS package 'SQL execute task'. that script is in that task. when the package run, is comes to that task and fail with the error.thanks.Thu, 12 Apr 2012 23:27:29 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxI think your DDL and sample data script is not correct. Its returning errors. I think you should check it.Thu, 12 Apr 2012 22:33:28 GMTvinu512RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]Grass (4/12/2012)[/b][hr]Hi Vinu:I checked entity_id,and user_id are retruning multiple records in a table. So, what field do I need in my statement as a distinct.Are these entity_id,user_id ones? or something else.Thanks.[/quote]This error: "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , &gt;, &gt;= or when the subquery is used as an expression."Do you get it only once??.....you can click/double click on it and get to know which part of your code has the error.Try using "SELECT DISTINCT" or "SELECT 1" in the Subqueries which you think might be causing the error(the subqueries returning entity_id and user_id). This way only one value will be returned and your error will be taken care of.Hope this helps you.Please try it and let us knowThu, 12 Apr 2012 22:28:16 GMTvinu512RE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[code="plain"][/code]Thu, 12 Apr 2012 14:07:40 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]suhailtajraja (4/12/2012)[/b][hr]Hi:I have created all the tables DDL and select data statement. whats next?thanks.[/quote]Post it?Thu, 12 Apr 2012 13:44:54 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxHi:I have created all the tables DDL and select data statement. whats next?thanks.Thu, 12 Apr 2012 13:43:30 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]suhailtajraja (4/12/2012)[/b][hr]the table that i have provided is the actual table. is that needs to be in new temp table so that i dont mess with the actual table? also, what other tables needs to be just like that.thanks.[/quote]All of them. We can't run queries against tables we don't have.int_maslon_matter_recentint_aux_projectint_aux_lst_customint_aux_lstint_userThu, 12 Apr 2012 11:06:35 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]suhailtajraja (4/12/2012)[/b][hr]the table that i have provided is the actual table. is that needs to be in new temp table so that i dont mess with the actual table? also, what other tables needs to be just like that.thanks.[/quote]from reading your original query it looks like we need the following tables: int_aux_project int_aux_lst_custom int_user int_maslon_matter_recentif you are pulling data from any other tables we will need those to.Thu, 12 Apr 2012 11:05:23 GMTCapnHectorRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxthe table that i have provided is the actual table. is that needs to be in new temp table so that i dont mess with the actual table? also, what other tables needs to be just like that.thanks.Thu, 12 Apr 2012 11:03:01 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxYou already provided that table. Here it is all at once.[code]CREATE TABLE [dbo].[INT_AUX_FAVORITES]([USER_ID] [int] NOT NULL,[TYP_IND] [smallint] NOT NULL,[ENTITY_ID] [int] NOT NULL,[ENTITY_SRC_ID] [int] NOT NULL,[DOMAIN_ID] [int] NOT NULL,[ENTITY_NM] [nvarchar](150) NOT NULL,[ENTITY_TYP_ID] [int] NULL,[AUTO_OPEN_IND] [smallint] NOT NULL,[MAPI_IND] [smallint] NOT NULL,[RESERVED1_IND] [int] NULL,[RESERVED2_IND] [int] NULL,[RESERVED3_IND] [int] NULL,[RESERVED4_IND] [int] NULL,[RESERVED5] [nvarchar](254) NULL,[RESERVED6] [nvarchar](254) NULL,[GROUP_ID] [int] NOT NULL,CONSTRAINT [XPKAUX_FAVORITES] PRIMARY KEY CLUSTERED([USER_ID] ASC,[TYP_IND] ASC,[ENTITY_ID] ASC,[ENTITY_SRC_ID] ASC,[DOMAIN_ID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY]goinsert INT_AUX_FAVORITESSELECT '0','6','58757','2','2','User-Preferences-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','59631','2','2','Co-Client-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','60775','2','2','Estate-Planning-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','60778','2','2','Company-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','61435','2','2','Attorney-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','61543','2','2','Paralegal-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','5','3','0','2','Estate-Planning','0','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','5','6','0','2','2006-Strategic-Transaction','0','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','6','-10020','2','2','*-Send-No-Marketing-Communications','9','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','6','-10019','2','2','Former-Clients','16','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0'[/code]Now we just something similar for all the other tables.Thu, 12 Apr 2012 10:42:47 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxThe select statements you have made is right. Now what next with it. Do i need to create a sample table to put this into?thanksThu, 12 Apr 2012 10:37:12 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxdunno if it matches the table that was posted, but here's the data as a select to show what we are looking for:I've got a pair of macros for hacking strings that people post to turn them into SELECt statements that can be used for INSERT INTO or CTE's:[code]SELECT '0','6','58757','2','2','User-Preferences-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','59631','2','2','Co-Client-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','60775','2','2','Estate-Planning-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','60778','2','2','Company-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','61435','2','2','Attorney-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '0','6','61543','2','2','Paralegal-Information','20','0','1','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','5','3','0','2','Estate-Planning','0','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','5','6','0','2','2006-Strategic-Transaction','0','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','6','-10020','2','2','*-Send-No-Marketing-Communications','9','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0' UNION ALLSELECT '1','6','-10019','2','2','Former-Clients','16','0','0','NULL','NULL','NULL','NULL','NULL','NULL','0'[/code]Thu, 12 Apr 2012 10:26:27 GMTLowellRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]suhailtajraja (4/12/2012)[/b][hr]I don't understand how to do this in a insert into format. please give explain step by stepthanks[/quote]Read the first article I reference below in my signature block.Thu, 12 Apr 2012 10:00:30 GMTLynn PettisRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxI don't understand how to do this in a insert into format. please give explain step by stepthanksThu, 12 Apr 2012 09:59:07 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]suhailtajraja (4/12/2012)[/b][hr]Here is the sample data from table int_aux_favorites.USER_ID TYP_IND ENTITY_ID ENTITY_SRC_ID DOMAIN_ID ENTITY_NM ENTITY_TYP_ID AUTO_OPEN_IND MAPI_IND RESERVED1_IND RESERVED2_IND RESERVED3_IND RESERVED4_IND RESERVED5 RESERVED6 GROUP_ID0 6 58757 2 2 User Preferences Information 20 0 1 NULL NULL NULL NULL NULL NULL 00 6 59631 2 2 Co-Client Information 20 0 1 NULL NULL NULL NULL NULL NULL 00 6 60775 2 2 Estate Planning Information 20 0 1 NULL NULL NULL NULL NULL NULL 00 6 60778 2 2 Company Information 20 0 1 NULL NULL NULL NULL NULL NULL 00 6 61435 2 2 Attorney Information 20 0 1 NULL NULL NULL NULL NULL NULL 00 6 61543 2 2 Paralegal Information 20 0 1 NULL NULL NULL NULL NULL NULL 01 5 3 0 2 Estate Planning 0 0 0 NULL NULL NULL NULL NULL NULL 01 5 6 0 2 2006 Strategic Transaction 0 0 0 NULL NULL NULL NULL NULL NULL 01 6 -10020 2 2 * Send No Marketing Communications 9 0 0 NULL NULL NULL NULL NULL NULL 01 6 -10019 2 2 Former Clients 16 0 0 NULL NULL NULL NULL NULL NULL 0[/quote]I don't see how we can geet this data into the table you provided. This needs to be in a readily consumable format, such as a series of INSERT INTO statements.Thu, 12 Apr 2012 09:41:01 GMTLynn PettisRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxPosting them as insert statements would be the preferred method. That way the people offering to help get your data in an easily consumable format.Thu, 12 Apr 2012 09:40:16 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[code="plain"][/code]Thu, 12 Apr 2012 09:37:36 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxThere are far more tables than just the favorites. Also, we need sample data for each table.Thu, 12 Apr 2012 09:35:01 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxThanks for the reply. I will try this. Which part of the code needs to be replaced for this the code you provided.Thu, 12 Apr 2012 09:14:41 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxthis is just a shot in the dark but I assume you passing in @Matter_ID and @Project_ID?See if this select would get all int_aux_favorites that you want deleted for a given matter_ID and Project_ID.[code]select iaf.* from int_maslon_matter_recent immrjoin int_aux_project iap on iap.project_cd = immr.MatterNumberjoin int_aux_lst_custom ialc on immr.TimeKeeperNumber = ialc.string_value and LST_CUSTOM_DEF_ID = '-10017'join int_user iu on iu.listing_id = ialc.listing_idjoin int_aux_favorites iaf on iaf.user_id = iu.user_id and iaf.entity_id = iap.project_idwhere immr.entity_id = @Project_IDand immr.MatterNumber = @Matter_ID[/code]Thu, 12 Apr 2012 09:00:14 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxI can pretty much guarantee there is no need for a cursor for this. This is nothing more than a delete statement inside a loop. This can pretty easily be converted to a single delete statement. Once you post the ddl and some sample data we can knock this out pretty quick.Thu, 12 Apr 2012 08:47:12 GMTSean LangeRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]suhailtajraja (4/12/2012)[/b][hr]Sorry,Don't understand what is DDL means and what data you need to see, the table that used in the select statement.thanks[/quote]DDL - Data Defintion Language. In this case it means the CREATE TABLE statements used to create the tables.Data - Sample data for the table(s) that you provide the DDL for. The sample data needs to be provided in a readily consumable format, a series of INSERT INTO statements usually works best.Thu, 12 Apr 2012 08:34:25 GMTLynn PettisRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxSorry,Don't understand what is DDL means and what data you need to see, the table that used in the select statement.thanksThu, 12 Apr 2012 08:24:11 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspx[quote][b]suhailtajraja (4/12/2012)[/b][hr]Hi Vinu:I checked entity_id,and user_id are retruning multiple records in a table. So, what field do I need in my statement as a distinct.Are these entity_id,user_id ones? or something else.Thanks.[/quote]can you post DDL and sample data. that will really help us out in figuring out what will cut the multiple rows. also there may be a way to get rid of the cursor which we will see once you post sample data and DDL statements.Thu, 12 Apr 2012 08:13:33 GMTCapnHectorRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxHi Vinu:I checked entity_id,and user_id are retruning multiple records in a table. So, what field do I need in my statement as a distinct.Are these entity_id,user_id ones? or something else.Thanks.Thu, 12 Apr 2012 07:52:07 GMTGrassRE: Need Help with the Error 'Subquery returned more than 1 value'.http://www.sqlservercentral.com/Forums/Topic1282061-1292-1.aspxYou should check your table for duplicates because one of your sub queries is returning multiple records from the table based on your parameters. This could happen if you have duplicate records.Try using Select Distinct OR Select 1 to avoid the error.Vinu VijayanThu, 12 Apr 2012 01:13:51 GMTvinu512