• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1527
  • Last Modified:

UPdate statement with a cross apply

I have the following statement, It will not run giving me the following message
Msg 102 Level 15 State 1 Line 10
Incorrect syntax near ')'.

here is the code
update co_customer_x_address
set cxa_on_hold_flag = '1'
from

(select distinct a1.cxa_mailing_label, a1.cxa_adr_key, M.cxa_adr_key
from co_customer_x_address a1
outer apply
(select a2.cxa_adr_key from co_customer_x_address a2
where a1.cxa_adr_key = a2.cxa_adr_key) M
Where a1.cxa_adr_key = '4490a7ff-cbfe-4386-8643-ec8cec854410')

If I run the Middle Select statement by it self it runs fine and returns the exact expected results but when I try to add the upate statemetn it doesn't work.
Anyone know what I am doing wrong and can guide or help be figure this out.
 
0
smcrocker66062
Asked:
smcrocker66062
  • 2
1 Solution
 
JestersGrindCommented:
Try this:
Greg

update co_customer_x_address
set cxa_on_hold_flag = '1'
from 
((select distinct a1.cxa_mailing_label, a1.cxa_adr_key, M.cxa_adr_key
from co_customer_x_address
Where a1.cxa_adr_key = '4490a7ff-cbfe-4386-8643-ec8cec854410') a1
outer apply
(select a2.cxa_adr_key from co_customer_x_address a2
where a1.cxa_adr_key = a2.cxa_adr_key) M) 

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should do:
update a1
  set cxa_on_hold_flag = '1'
from co_customer_x_address a1
join co_customer_x_address a2
  on a1.cxa_adr_key = a2.cxa_adr_key
Where a1.cxa_adr_key = '4490a7ff-cbfe-4386-8643-ec8cec854410'

Open in new window

0
 
smcrocker66062Author Commented:
No, it will not even parse out in Query Analyzer
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'outer'.
Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'M'.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please try my suggestion?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now