Solved

UPdate statement with a cross apply

Posted on 2009-04-07
5
988 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
  • 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 142

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 142

Expert Comment

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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article describes some very basic things about SQL Server filegroups.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now