hello friends.. I am newbie for sql server...I having a problem when executing this procedure .... ALTER PROCEDURE [dbo].[spgetvalues] @Uid intASBEGIN SET NOCOUNT ON; select DATEPART(year, c.fy)as fy, (select contribeamount from wh_contribute where and contribename like 'Retire-Plan B-1% JRF' ) as survivorship, (select contribeamount from wh_contribute where and contribename like 'Gross Earnings' and ) as ytdgross, (select contribeamount from wh_contribute where and contribename like 'Retire-Plan B-1.5% JRP') as totalcontrib, from wh_contribute c where c.uid=@Uid Order by fy Asc .....what is the wrong here?? " Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."please reply asap...
I am getting 2 resultsets depending on conditon, In the secondconditon i am getting the above error could anyone help me..........CREATE proc sp_count_AllNewsPapers@CustomerId intasdeclare @NewsId intset @NewsId = (select NewsDelId from NewsDelivery whereCustomerId=@CustomerId )if not exists(select CustomerId from NewsDelivery whereNewsPapersId=@NewsId)beginselect count( NewsPapersId) from NewsPapersendif exists(select CustomerId from NewsDelivery whereNewsPapersId=@NewsId)beginselect count(NewsDelId) from NewsDelivery whereCustomerid=@CustomeridendGO
I've running the below query for months ans suddenly today started getting the following error :"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
Any ideas as to why??
SELECT t0.DocNum, t0.Status, t0.ItemCode, t0.Warehouse, t0.OriginNum, t0.U_SOLineNo, ORDR.NumAtCard, ORDR.CardCode, OITM_1.U_Cultivar, RDR1.U_Variety, (SELECT OITM.U_Variety FROM OWOR INNER JOIN WOR1 ON OWOR.DocEntry = WOR1.DocEntry INNER JOIN OITM INNER JOIN OITB ON OITM.ItmsGrpCod = OITB.ItmsGrpCod ON WOR1.ItemCode = OITM.ItemCode WHERE (OITB.ItmsGrpNam = 'Basic Fruit') AND (OWOR.DocNum = t0.DocNum)) AS Expr1, OITM_1.U_Organisation, OITM_1.U_Commodity, OITM_1.U_Pack, OITM_1.U_Grade, RDR1.U_SizeCount, OITM_1.U_InvCode, OITM_1.U_Brand, OITM_1.U_PalleBase, OITM_1.U_Crt_Pallet, OITM_1.U_LabelType, RDR1.U_DEPOT, OITM_1.U_PLU, RDR1.U_Trgt_Mrkt, RDR1.U_Wrap_Type, ORDR.U_SCCode FROM OWOR AS t0 INNER JOIN ORDR ON t0.OriginNum = ORDR.DocNum INNER JOIN RDR1 ON ORDR.DocEntry = RDR1.DocEntry AND t0.U_SOLineNo - 1 = RDR1.LineNum INNER JOIN OITM AS OITM_1 ON t0.ItemCode = OITM_1.ItemCode WHERE (t0.Status <> 'L')
Right now I have to do something like this and it is time consuming every time I have to query a specific table...
SELECT lots_of_columns FROM table WHERE (column5 = '1' OR column6 = '1' OR column7 = '1' OR column8 = '1' OR column9 = '1' OR column10 = '1' OR column11 = '1' OR column12 = '1') AND other_query_critiera_here
Typing out the OR statement gets long, time consuming and prone to errors because that first where line with all the ORs can sometimes have 20+ ORs in it. As some insight, the columns are text columns, sometimes they have data, sometimes they are NULL. Sometimes they have the same data (i.e., column5 and column6 and column12 could both have '1' as values).
i am trying to run Select query to get "application name" and "role" for each user in the DB problem is that each user has more than one App that he is useing and for each App he can have more than one role
My code is:
Code: select top 100 username, (Select b.name from application b inner join userroleapplication c on b.applicationID = c.applicationID ) Application, (select name from role d, userroleapplication gr where gr.roleID = d.roleID and gr.userID = a.userID) role from users a where username in ( 'username' )
i know where is the problem but i cant figure how to fix this
I have a simple update query that looks like this:
Update Table1 set midpointDate = (select dateadd(day,(datediff(day,startDate,endDate)/2),starteDate) from Table1) where Table1.RowID = Table1.RowID
I am receiving the following error: "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."Yes, it is all contained in the same table.
SET @parentPage = (SELECT [frntPage] FROM [OLissue], [Outlook] WHERE ([Outlook].[issueID] = @OLissueID AND [Outlook].[issueID] = [OLissue].[issueID] AND [OLissue].[frntPage] IS NOT NULL AND [Outlook].[parent] IS NOT NULL))
IF @parentPage IS NOT NULL
IF exists (SELECT [Outlook].[ID], [Outlook].[title], [Outlook].[name], [Outlook].[issueID] FROM [OLissue], [Outlook] WHERE ([Outlook].[issueID] = @OLissueID AND [Outlook].[issueID] = [OLissue].[issueID])) SELECT [ID], [title], [name], [issueID] FROM [Outlook] WHERE ([issueID] = @OLissueID)
SELECT DISTINCT NULL ID, 'No parent page yet' title FROM [Outlook]
And I kept getting this error when testing in SQL Management Studio.
Msg 512, Level 16, State 1, Procedure parentPage, Line 19
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
select t1.a, (select t2.b from t2 where t1.c = t2.c) b from t1 I need to write that kind of sql to return me single value a and multiple values b on each of lines, like a b ---------------------------- tom small,big,hugh But if I execute that sql, I would get error like 'select Subquery returned more than 1 value'. Please help me find a solution, thanks!
Hi i am a newbie in sql so any help would be appreciated. i have a serverlog table that initially had one server and different functions types, my sql query got a percentage of the execution times for the different functions and all worked well, however as soon as i put more servers in to the table i got the following error...
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
Here is my SQL, the problem is with the sub queries returning more than one server type... Hope somebody can help and thanks in advance..
SELECT server, [function], prelimquery * 100 AS [%OverallProcessingTime] FROM (SELECT server, [function], subquerya / (SELECT subqueryb FROM (SELECT totalallreqexec * (SELECT AVG([exec_time]) FROM llserverlogs) AS subqueryb FROM (SELECT COUNT(*) AS totalallreqexec FROM llserverlogs) DERIVEDTBL) DERIVEDTBL) AS prelimquery FROM (SELECT server, [function], NoRequestExecutions * (SELECT avgexectime FROM (SELECT DISTINCT server, AVG(exec_time) AS avgexectime FROM llserverlogs GROUP BY server) DERIVEDTBL) AS subquerya FROM (SELECT DISTINCT server, [function], COUNT(*) AS NoRequestExecutions FROM llserverlogs GROUP BY server, [function]) DERIVEDTBL) DERIVEDTBL) DERIVEDTBL
when I run the query UPDATE dbhal.dbo.tblUser SET vchrFirstName = FirstName, vchrLastName = LastName, vchrLogin = LoginName, bitActive = Active, vchrEmailAddress = EmailAddress FROM TempEmployee, tbluser where EmployeeID = intEmp and vchrcompid = 'sam'
and there is trigger
CREATE TRIGGER UPDATE_tblUser ON tblUser FOR UPDATE AS DECLARE @CompanyId as varchar(20), @intUid as int SET @CompanyId =(Select vchrCompID from deleted) Set @intUid = (Select intUid from deleted) IF @CompanyId = 'sam' BEGIN UPDATE [dbPortal].[dbo].tblUser SET intEmp = (Select intEmp from inserted), vchrCompID = (Select vchrCompID from inserted), vchrPwd = (Select vchrPwd from inserted), vchrLogin = (Select vchrLogin from inserted), vchrFirstName = (Select vchrFirstName from inserted) , vchrLastName = (Select vchrLastName from inserted), vchrEmailAddress = (Select vchrEmailAddress from inserted), bitActive = (Select bitActive from inserted), intPWDAttempt = (Select intPWDAttempt from inserted), vchrCreatedWho = (Select vchrCreatedWho from inserted), dtmCreatedDate = (Select dtmCreatedDate from inserted), vchrModifiedWho = (Select vchrModifiedWho from inserted), dtmModifiedDate = (Select dtmModifiedDate from inserted) WHERE intUID = @intUid END
I get the error. What can I do to get this to run?
"Subquery returned more than 1 value." etc when running a query on a linked server through OpenQuery. This returns around 6 values (some of them are fairly long varchar's). When running another query the same way which returns 2 values, it works fine.
The problem query also works fine when run locally. It's calling a User-Defined Functions which returns a table, but the second query which works fine also does this.
Where can this subquery be ? Inside the UDF (shouldn't matter, should it?) ?
Am getting error:- Subquery returned more than one value,that is not permitted when sub query follows
=,<,>.................................Below is my query declare @WorkOrder as nvarchar(10) Set @WorkOrder =( Select X.PrjCode from OPRJ X Where X.PrjCode='[%1]')
SELECT L.Project ,l.U_PINo as [Indent No], M.DocNum AS 'GRN No', M.DocDate as 'Date', M.CardName as 'Vendor Name',L.ItemCode,l.Dscription,l.Quantity,l.unitMsr as'UOM',l.Price,l.DiscPrcnt ,L.LineTotal, isnull((SELECT (TaxSum) FROM PDN4 where statype=-90 and DocEntry=M.DocEntry and L.LineNum =PDN4.LineNum),0) +
Hi group I get the above error in my SP when the tblHolidayDates has more than one record. Here is my SP: begin
if datediff(day,getdate()-10 ,(Select HolidayDate from tblHolidayDates))= 3 AND DATEPART(dw,(select holidaydate from tblHolidayDates)) = 1 -- Monday Date SELECT su.SuspensionID, su.ConsentNo, si.SiteID, si.NameNo + ' ' + si.Address1 AS SiteAddress, si.SiteDesc, si.SuspensionStart, si.SuspensionEnd, si.Address1, si.BaysAttached, rd.RefValue AS NoticeDays, si.MergeID FROM Suspension su INNER JOIN SiteData si ON su.SuspensionID = si.SuspensionID INNER JOIN RefData rd ON si.NotReq = rd.RefCode WHERE su.Status = 'ACT' and si.Archived = 'N' and (datediff(day, getdate()-10 , si.SuspensionStart) = rd.RefValue OR (datediff(day, (Select holidaydate from tblHolidayDates), si.SuspensionStart)= rd.RefValue + 2) or datediff(day,(Select holidaydate from tblHolidayDates), si.SuspensionStart)=rd.RefValue + 1) end
I have some code that calls a stored procedure on SQL Server 2005 using the Microsoft JDBC driver 1.1. The code normally works however, every once in a while an exception is thrown:
com.microsoft.sqlserver.jdbc.SQLServerException: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !, <,<=, >, >=, or when the subquery is used as an expression.
Generally, this has been resolved by restarting SQL Server 2005, but why is it showing up to being with?
ALTER Procedure [dbo].[addRecord] @userID int, @itemID int, @info varchar(50), @comment varchar(50), @output int output AS
Declare @dateSubmitted datetime set @dateSubmitted = getDate();
--Insert the new record. THIS TABLE has an ID identity Primary Key --column that auto-increments. insert into RecordTable (UserPerson, Information, DateSubmitted) values (@userID, @info, @dateSubmitted);
---Get the ID Assigned in the record table. The Item table ---has a Foreign key on this column. Declare @assignedID int set @assignedID = (select ID from RecordTable where DateSubmitted = @dateSubmitted)
/**Set the output parameter.*/ set @output = @assignedID;
--Now update the Item Table. insert into Item (ID, RecordID, Comment) values (@item,@assignedID, @comment);
The error below is encounter when a mass update is attempted on our employee table.
Server: Msg 512, Level 16, State 1, Procedure emp_lock_id, Line 8 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.
The Trigger code is below
CREATE TRIGGER emp_lock_id ON dbo.EMPLOYEE FOR UPDATE AS DECLARE @NEXT_NUM DECIMAL(17, 12) DECLARE @NEW_NUM DECIMAL(17, 9) DECLARE @OLD_LOCK_ID DECIMAL DECLARE @NEW_LOCK_ID DECIMAL SET @OLD_LOCK_ID = (SELECT EMP_LOCK_ID FROM DELETED) SET @NEW_LOCK_ID = (SELECT EMP_LOCK_ID FROM INSERTED) IF @OLD_LOCK_ID <> @NEW_LOCK_ID BEGIN RAISERROR('Record Modified by different user.', 16, 1) ROLLBACK TRANSACTION END ELSE BEGIN SET @NEXT_NUM = (convert(decimal(17,12), getdate())) SET @NEW_NUM = @NEXT_NUM * 1000 UPDATE EMPLOYEE SET EMP_LOCK_ID = (@NEW_NUM - floor(@NEW_NUM)) * 1000000000 FROM EMPLOYEE, INSERTED WHERE EMPLOYEE.EMP_EMPLOYEE_ID = INSERTED.EMP_EMPLOYEE_ID END
Hi, I am using .NET sqlBulkCopy to insert several rows at once into my sql table. Yesterday I created a simple trigger on this table to take the primary key of the inserted row and place into another table. Fairly straightforward I thought, but I keep getting this error when inserting 2 or more rows (works fine with one row): "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <= , >, >= or when the subquery is used as an expression. The statement has been terminated." To test this, I changed the sqlBulkCopy into individual INSERT statements in a for each loop and then it works perfectly, so I know that it's definitely the sqlBulkCopy causing the problem, not the trigger itself. Here is my trigger code anyway: alter trigger tg_InsertClaim on AuditItemfor insertas declare @AuditItemID as intset @AuditItemID = (select i.AuditItemID from inserted i inner join dbo.AuditItem a ON i.AuditItemID = a.AuditItemID) insert into Claim (AuditItemID) VALUES (@AuditItemID) Thanks!
I am attempting to Insert multiple rows in a table by passing DataTable to a Stored Proc. My code is the same as the examples on the net, however when I execute the code I receive the Subquery returned more than 1 value error.
I first created up a User-Defined Table Type
My stored proc is as follows:
ALTER PROCEDURE [KCC].[Insert_MaterialJobMtl] @MtlTblMaterialType READONLY AS BEGIN Set NOCOUNT ON;
Please try the following, see that trigger is getting invoked, even if there is no row inserted into trigger table.
drop TABLE X GO CREATE TABLE X ( x1 bigint NOT NULL , x2 nvarchar(40) ) GO drop TABLE Y CREATE TABLE Y ( y1 bigint NOT NULL , y2 nvarchar(40) ) GO CREATE TRIGGER trg1 ON X FOR INSERT AS BEGIN DECLARE @prfirststatus INTEGER, @newcontextid NCHAR SELECT @newcontextid = x2, @prfirststatus = x1 FROM inserted PRINT 'See the trigger getting invoked without even a single ' + ' row being inserted in table X and values passed to this ' + ' triggers are inserted.x2 = ' + @newcontextid insert into Y values (@prfirststatus,@newcontextid) END GO insert into X SELECT y1, 'x' from Y where y2 = 'DOESNTEXIST'
Hey, I'm referencing a database about a fictitious IT company, and I'm trying to answer the following statement:
Determine who has logged the most hours. Create a SELECT statement to return their name and the max hours they have worked. NOTE: This is a tougher one but looking into using a Subquery and use the HAVING statement.
I've written this so far, and although it does give me the right answer (there is only one employee in the DB who has worked on projects) it is not entirely correct. Basically there is no subquery, and it doesn't really show who has worked the max hours:
SELECT EMPLOYEE_NAME 'Employee Name', SUM(HOURS_LOGGED) 'Maximum Hours Logged' FROM PROJECT_EMPLOYEE PE INNER JOIN PROJECT_HOURS PH ON PH.EMPLOYEE_ID = PE.EMPLOYEE_ID INNER JOIN PROJECT P ON P.PROJECT_ID = PH.PROJECT_ID GROUP BY PE.EMPLOYEE_NAME