Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with Where clause in Trigger

Status
Not open for further replies.

bustercoder

Programmer
Mar 13, 2007
96
Hello, I am trying to add a where clause to make sure I have unique tracking numbers going in. But where I try to add a check in my where clause, it complains with:

"The column prefix 'SOP10107' does not match with a table name or alias name used in the query."

Here is the trigger with commented out where clause:
ALTER TRIGGER [dbo].[trig_updateTrackingNumber] ON [dbo].[TBZ_Shipments_Import]
FOR INSERT, UPDATE, DELETE
AS
begin
SET NOCOUNT ON

if exists (select * from deleted)
begin
delete SOP10107
from SOP10107 utn inner join
deleted on (utn.SOPNUMBE = deleted.ORDER_ID)
end

if exists (select * from inserted)
begin
insert SOP10107
select ORDER_ID, 3, TRACKING_NUMBER
from inserted --where SOP10107.Tracking_Number <> inserted.TRACKING_NUMBER
end
end

Any help greatly appreciated.

Thanks,
Buster
 
Make sure you test this VERY well.

Code:
[COLOR=blue]if[/color] exists ([COLOR=blue]select[/color] * [COLOR=blue]from[/color] inserted)
[COLOR=blue]begin[/color]
  [COLOR=blue]insert[/color] SOP10107
  [COLOR=blue]select[/color] ORDER_ID, 3, TRACKING_NUMBER
  [COLOR=blue]from[/color]   inserted
         [COLOR=#FF00FF]Left[/color] [COLOR=blue]Join[/color] SOP10107
           [COLOR=blue]On[/color] SOP10107.Tracking_Number = inserted.TRACKING_NUMBER
  [COLOR=blue]Where[/color]  SOP10107.Tracking_Number [COLOR=blue]Is[/color] NULL
[COLOR=blue]end[/color]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I will George. You're really helping me learn and I really appreciate it.
Buster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top