Gordon Hughes
asked on
Help with Update Query
What is wrong with this:-
PURREQH, COSTCTR
update PURREQH
set PURREQH.COSTCENTER = PURREQH.[DESTID]
where PURREQH.COSTCENTER is null
and PURREQH.DESTID in COSTCTR.COSTCENTER
get the following error message:-#
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'COSTCTR'.
PURREQH, COSTCTR
update PURREQH
set PURREQH.COSTCENTER = PURREQH.[DESTID]
where PURREQH.COSTCENTER is null
and PURREQH.DESTID in COSTCTR.COSTCENTER
get the following error message:-#
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'COSTCTR'.
The table names don't go at the top like that. You should have:
update PURREQH
set PURREQH.COSTCENTER = PURREQH.[DESTID]
FROM PURREQH
where PURREQH.COSTCENTER is null
and PURREQH.DESTID in (SELECT COSTCENTER FROM COSTCTR)
update PURREQH
set PURREQH.COSTCENTER = PURREQH.[DESTID]
FROM PURREQH
where PURREQH.COSTCENTER is null
and PURREQH.DESTID in (SELECT COSTCENTER FROM COSTCTR)
ASKER
Hi
Have tried dkrollCTN solution
The query runs but have an error as I did not take account of null
this is where there are nulls in the PURREQH.[DESTID]
so get the following:
Msg 515, Level 16, State 2, Procedure PURREQ_A, Line 87
Cannot insert the value NULL into column 'SESSIONID', table 'MP2LIVE.dbo.MP2TRIGGER'; column does not allow nulls. INSERT fails.
The statement has been terminated.
How do I change the query
Gordon
Have tried dkrollCTN solution
The query runs but have an error as I did not take account of null
this is where there are nulls in the PURREQH.[DESTID]
so get the following:
Msg 515, Level 16, State 2, Procedure PURREQ_A, Line 87
Cannot insert the value NULL into column 'SESSIONID', table 'MP2LIVE.dbo.MP2TRIGGER'; column does not allow nulls. INSERT fails.
The statement has been terminated.
How do I change the query
Gordon
update PURREQH
set PURREQH.COSTCENTER = PURREQH.[DESTID]
FROM PURREQH
where PURREQH.COSTCENTER is null
and PURREQH.DESTID in (SELECT COSTCENTER FROM COSTCTR WHERE COSTCENTER IS NOT NULL)
set PURREQH.COSTCENTER = PURREQH.[DESTID]
FROM PURREQH
where PURREQH.COSTCENTER is null
and PURREQH.DESTID in (SELECT COSTCENTER FROM COSTCTR WHERE COSTCENTER IS NOT NULL)
ASKER
Hi
Tried that, but still get
Msg 515, Level 16, State 2, Procedure PURREQ_A, Line 87
Cannot insert the value NULL into column 'SESSIONID', table 'MP2LIVE.dbo.MP2TRIGGER'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I think the issue is where the PURREQH.DESTID has a null value, but I may be wrong!
Gordon
Tried that, but still get
Msg 515, Level 16, State 2, Procedure PURREQ_A, Line 87
Cannot insert the value NULL into column 'SESSIONID', table 'MP2LIVE.dbo.MP2TRIGGER'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I think the issue is where the PURREQH.DESTID has a null value, but I may be wrong!
Gordon
Can you post the code from the MP2TRIGGER in table MP2LIVE?
What if you just disabled the trigger?
ASKER
Couple of things
Firstly I think i need to update the table PURREQ rather than the view PURREQH
so tried this
update PURREQ
set PURREQ.COSTCENTER = PURREQ.[DESTID]
FROM PURREQ
where PURREQ.COSTCENTER is null
and PURREQ.DESTID in (SELECT COSTCENTER FROM COSTCTR WHERE COSTCENTER IS NOT NULL)
but still get the same error message
MP2LIVE.dbo.MP2TRIGGER' is a table, cannot see any trigger code
Not sure what to do next, apart from give up today and go and have my dinner!!
Gordon
Firstly I think i need to update the table PURREQ rather than the view PURREQH
so tried this
update PURREQ
set PURREQ.COSTCENTER = PURREQ.[DESTID]
FROM PURREQ
where PURREQ.COSTCENTER is null
and PURREQ.DESTID in (SELECT COSTCENTER FROM COSTCTR WHERE COSTCENTER IS NOT NULL)
but still get the same error message
MP2LIVE.dbo.MP2TRIGGER' is a table, cannot see any trigger code
Not sure what to do next, apart from give up today and go and have my dinner!!
Gordon
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Hi
How do I disable the trigger?
Gordon
How do I disable the trigger?
Gordon
Actually the issue is here:
PURREQ_A
Is there that trigger on the table?
PURREQ_A
Is there that trigger on the table?
ASKER
Hi
PURREQ_A is the trigger on PURREQ table
Do you know how I could temporary disable it?
Gordon
PURREQ_A is the trigger on PURREQ table
Do you know how I could temporary disable it?
Gordon
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Hi
Will try the code, but when you right. Click there is not an option to disable the trigger
Gordon
Will try the code, but when you right. Click there is not an option to disable the trigger
Gordon
You may not have permissions.
What account are you using?
What account are you using?
ASKER
Hi
Am using the sa account
Gordon
Am using the sa account
Gordon
ASKER
Hi
I used the disaable command, worked OK and then I could run
update PURREQ
set PURREQ.COSTCENTER = PURREQ.[DESTID]
FROM PURREQ
where PURREQ.COSTCENTER is null
and PURREQ.DESTID in (SELECT COSTCENTER FROM COSTCTR WHERE COSTCENTER IS NOT NULL)
It worked OK then enabled the trigger
Job Done
I used the disaable command, worked OK and then I could run
update PURREQ
set PURREQ.COSTCENTER = PURREQ.[DESTID]
FROM PURREQ
where PURREQ.COSTCENTER is null
and PURREQ.DESTID in (SELECT COSTCENTER FROM COSTCTR WHERE COSTCENTER IS NOT NULL)
It worked OK then enabled the trigger
Job Done
ASKER
Was a little challenging, but got there with the help
I used the disaable command, worked OK and then I could run
There are two problems with this approach:
1. Security: The user must have ALTER permissions on the table .
2. Global scope: Disabling a TRIGGER not only affects your session, but also affects all sessions for all users.
There are two problems with this approach:
1. Security: The user must have ALTER permissions on the table .
2. Global scope: Disabling a TRIGGER not only affects your session, but also affects all sessions for all users.
ASKER
Hi
I used it only to run an update script
I then ran the enable code
Is this ok?
Gordon
I used it only to run an update script
I then ran the enable code
Is this ok?
Gordon
So long as you are OK with the security (or lack of) and no one else is using that table at that time you should be fine.
Mind you those are big ifs.
Mind you those are big ifs.
set p.CostCenter = p.DestID
from PURREQH p
join COSTCTR c on p.DESTID = c.CostCenter
where p.CostCenter is null