Solved

UPdate statement with a cross apply

Posted on 2009-04-07
5
834 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
Comment Utility
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
Comment Utility
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
Comment Utility
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]
Comment Utility
please try my suggestion?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…

772 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