?
Solved

UPdate statement with a cross apply

Posted on 2009-04-07
5
Medium Priority
?
1,318 Views
Last Modified: 2012-05-06
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
Comment
Question by:smcrocker66062
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 21

Expert Comment

by:JestersGrind
ID: 24089986
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 24090653
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
 

Author Comment

by:smcrocker66062
ID: 24090726
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24090885
please try my suggestion?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question