Solved

UPdate statement with a cross apply

Posted on 2009-04-07
5
1,221 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 500 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…

691 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