472,332 Members | 1,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,332 software developers and data experts.

trigger:-Subquery returned more than 1 value. This is not permitted when the subquery

---------------trigger code
create trigger DeletepurchaseItems on table_purchaseitems
for delete,update
as
begin
select * from deleted
update table_STOCK set ostock=(ostock-(select sqty from deleted))
where itemcode=(select itemcode from deleted)and
coid=(select compid from deleted) and fycode=(select financialyear from deleted)
end
--------------------------------------------------------------
select * FROM TABLE_PURCHASEITEMS WHERE ORDERNO=12030
this statement return 2 records with same orderno

DELETE FROM TABLE_PURCHASEITEMS WHERE ORDERNO=12030
(how can i update table_stock if deleted table contains more than one record by using above delete trigger)
this will return
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.
plz help me what's remedy..
Feb 4 '08 #1
3 11233
deepuv04
227 Expert 100+
---------------trigger code
create trigger DeletepurchaseItems on table_purchaseitems
for delete,update
as
begin
select * from deleted
update table_STOCK set ostock=(ostock-(select sqty from deleted))
where itemcode=(select itemcode from deleted)and
coid=(select compid from deleted) and fycode=(select financialyear from deleted)
end
--------------------------------------------------------------
select * FROM TABLE_PURCHASEITEMS WHERE ORDERNO=12030
this statement return 2 records with same orderno

DELETE FROM TABLE_PURCHASEITEMS WHERE ORDERNO=12030
(how can i update table_stock if deleted table contains more than one record by using above delete trigger)
this will return
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.
plz help me what's remedy..
hi,

in the statement
set ostock=(ostock-(select sqty from deleted)) the select query will return more than one value

and all the select statements specified in the where clause may return more than one value which will give you the error

add a condtion to get a single value in the select statement which will resolve your problem.

I din't get the relation between TABLE_PURCHASEITEMS,table_stock and deleted tables

any way try the following query and make changes according to your requirement, probably will help you

update table_STOCK set ts.ostock = ts.ostock - d.sqty
from table_stock as ts inner join
deleted as d on ts.itemcode = d.itemcode and
ts.coid = d.compid and
ts.fycode = d.financialyear
where (your_conditonS) -- if you have any


thanks
Feb 4 '08 #2
hi i'm having thesame problem with these:
cmd.CommandText = "UPDATE [tblJan_Abra] SET february=(SELECT A.[february] FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 5.0;Database=D:\sample_project\SPRS\Book1.xls;HRD= YES','SELECT * FROM [Sheet1$]') AS A) WHERE ID BETWEEN 388 AND 729"
pls help
May 12 '10 #3
OraMaster
135 100+
@harmony123
Write your select subquery in such way that it should always return single row or you can use TOP 1 before listing the column name followed by SELECT keyword.
e.g. SELECT TOP 1 ename FROM EMP
It will always return single row.
May 12 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Pecos Bill | last post by:
Salve, non riesco a disabilitare un trigger su sqlserver nč da query analyzer, nč da enterprise manager. In pratica tal cosa riuscivo a farla in...
9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of...
1
by: Matik | last post by:
Hello to all, I have a small question. I call the SP outer the DB. The procedure deletes some record in table T1. The table T1 has a trigger...
3
by: takilroy | last post by:
Hi, Does anyone know of a simple way to do this? I want to create an insert trigger for a table and if the record already exists based on some...
0
by: Yogesh | last post by:
Hello Everyone I have to create Oracle tables in my application on the fly, which have an Autonumber field. So, everytime I create a table, I have...
2
by: Chris Gamache | last post by:
Tsearch2 comes with its own tsearch2 trigger function. You pass column names to it, and it puts a vanilla tsvector into the column named in TG_ARGV....
8
by: Frank van Vugt | last post by:
Hi, If during a transaction a number of deferred triggers are fired, what will be their execution order upon the commit? Will they be...
1
by: Daniel Schuchardt | last post by:
Hi list, i'm a bit confused. I have a table with a trigger after insert. It is possible that this trigger will do inserts in the same table, but...
9
by: steven | last post by:
Does anyone know how to do the following. I'm trying to mimic replication with triggers. I have 2 databases, each have these 2 tables. 1....
6
by: wugon.net | last post by:
Hi , Anyone know how to monitor db2 trigger activity ? We suffer some trigger issue , and we try to monitor trigger's behavior use event monitor...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.