Member of the LearnItFirst.com Video Training Network | LearnSqlServer.com | SQL SSIS Training | SQL Programming Tutorials |
LearnSqlServer.com Forums LearnSqlServer.com
Welcome Guest Search | New Posts | Members | Log In | Register

instead of insert for trigger problem Options
ejoeyz_85
Posted: Thursday, February 14, 2008 10:44:07 PM
Rank: Newbie

Joined: 1/14/2008
Posts: 5
Points: 15
Location: Sg Buloh
i have created trigger for instead of insert... below is the command



Quote:
create view v_OrganizationDetailType as
select Type_name, Org_name, Org_address, Org_tel_no, Org_fax_no, Org_email, Org_description
from OrganizationType inner join OrganizationDetail on OrganizationType.Type_application_id =OrganizationDetail.Type_application_id
go

create trigger tr_v_OrganizationDetailType on v_OrganizationDetailType instead of insert as
BEGIN
insert OrganizationType (Type_name)
select distinct inserted.Type_name
from inserted left join OrganizationType on inserted.Type_name = OrganizationType.Type_name
where OrganizationType.Type_name IS NULL /*** Exclude Organization Types already in the table ***/

insert OrganizationDetail (Org_name, Org_address, Org_tel_no, Org_fax_no, Org_email, Org_description, Type_application_id)
select distinct inserted.Org_name, inserted.Org_address, inserted.Org_tel_no,
inserted.Org_fax_no, inserted.Org_email, inserted.Org_description, OrganizationType.Type_application_id
from inserted inner join OrganizationType on inserted.Type_name = OrganizationType.Type_name
left join OrganizationDetail on inserted.Org_name = OrganizationDetail.Org_name
and inserted.Org_address = OrganizationDetail.Org_address
and inserted.Org_tel_no = OrganizationDetail.Org_tel_no
and inserted.Org_fax_no = OrganizationDetail.Org_fax_no
and inserted.Org_email = OrganizationDetail.Org_email
and inserted.Org_description = OrganizationDetail.Org_description
where OrganizationDetail.Org_name IS NULL /*** Exclude Organization Detail already in the table ***/

END -- trigger def
go




then, when i insert the values into table v_OrganizationDetailType, i got this message, Msg 512, Level 16, State 1, Procedure trg_InsertOrganization, Line 11
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.
below is the command for insert...

Quote:
insert v_OrganizationDetailType
select 'PTM', 'Sequ Inspection', 'Cheras', '0343234321', '0343234322', 'Sequ@inspec.com', 'Oil and Gas' UNION
select 'PTM', 'Alpha', 'Bangi', '0344567654', '0344567653', 'Alpha@yahoo.com', 'Hospitality Consultant'



what shud i do??? anyone plzz help me
Scott Whigham
Posted: Saturday, February 16, 2008 6:25:12 AM


Rank: Super Mod

Joined: 3/20/2006
Posts: 345
Points: 748
Location: Dallas, TX
Your error is not in the trigger/view code; it's from something else. Are you perhaps calling some function in the code that I don't see? There are no subqueries in the code you posted (that I see).
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
     
Don't Forget!
LearnItFirst.com
Don't Forget!
LearnWindows2003.com
 
Home | About Us | Support | Contact Us | Privacy | Site Map | Blogs Blogs Refer a Friend and Get a Free Subscription!
© Copyright 2004-2007 LearnItFirst.com LLC. All rights reserved. All trademarks remain the property of their respective owners.
This site is not affiliated in any way with the Microsoft Corporation.