Hi all,
I am trying to create a insert trigger that gets a value from the new record and use that to get additional data from other tables and update the new record
this is howfar i came:
create trigger trUpdateGEOData
on BK_Machine
after insert
as
update BK_Machine
set BK_Machine.LOC_Street = GEO_Postcode.STraatID, BK_Machine.Loc_City = GEO_Postcode.PlaatsID
from BK_Machine join GEO_Postcode on BK_Machine.loc_postalcode = GEO_Postcode.postcode, inserted
where BK_Machine.MachineID = Inserted.MachineID and BK_Machine.Loc_Postalcode = GEO_Postcode.postcode and BK_Machine.LOC_Doornumber <= GEO_Postcode.van and
BK_Machine.LOC_Doornumber <= GEO_Postcode.tem
Trigger runs fine but doesn't do a thing probably it can't find the machineid i think,
can someone help me?
Cheers WimmoSo sorry for posting such a stupid mistake from my hazy view today!!
< should be >
Trying to get awake today, sorry for the disturbance
Cheers Wimmo|||Cleaned up your code:create trigger trUpdateGEOData
on BK_Machine
after insert
as
update BK_Machine
set BK_Machine.LOC_Street = GEO_Postcode.STraatID,
BK_Machine.Loc_City = GEO_Postcode.PlaatsID
from BK_Machine
inner join GEO_Postcode on BK_Machine.loc_postalcode = GEO_Postcode.postcode
and BK_Machine.LOC_Doornumber <= GEO_Postcode.van
and BK_Machine.LOC_Doornumber <= GEO_Postcode.tem
inner join inserted on BK_Machine.MachineID = Inserted.MachineID
Now, it strikes me that the inner join on GEO_Postcode could return no records, in which case no BK_Machine records would be updated. It could also potentially return more than one record, in which case you would get unpredictable results for your update.|||Thanx Blindman,
What do you mean with the inner join: is it when there are more records inserted at the same time with the same machineid?
Wimmo
Showing posts with label additional. Show all posts
Showing posts with label additional. Show all posts
Subscribe to:
Posts (Atom)