473,394 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

What is wrong with SQL syntax

update prescriber_cross_ref
set preferred_in = 'Y' where prescriber_id =
(with temp1 as
(select A.prescriber_id,A.prescriber_dea_nb,A.prescriber_a ma_nb,A.prescriber_aoa_nb
from claimsa.tprscbr_prescribe1 A, prescriber_cross_ref B where
A.prescriber_id = B.prescriber_id),
with temp2 as

(select case when prescriber_dea_nb <>'' and prescriber_ama_nb <>''
and prescriber_aoa_nb <>'' then prescriber_id
when prescriber_dea_nb <>'' and prescriber_ama_nb
<>'' then prescriber_id
when prescriber_ama_nb <>'' and prescriber_aoa_nb <>''
then prescriber_id
when prescriber_ama_nb <>'' then prescriber_id
when prescriber_aoa_nb <>'' then prescriber_id

else
null
end as prescriber_id

from temp1))
select temp2.prescriber_id from temp2 where temp2.prescriber_id is not
null)
Nov 12 '05 #1
4 6286
DB2 does not support "Common Table Expression" (aka WITH) in a subquery.
What you can do is create an SQL Function with the WITH inside of it.

Cheers
Serge
Nov 12 '05 #2
You can use nested table expression instead of common table
expression.
(not always, but it seems true in your case)
Like this:
update prescriber_cross_ref
set preferred_in = 'Y'
where prescriber_id =
(select temp2.prescriber_id
from (select case
when prescriber_dea_nb <>''
and prescriber_ama_nb <>''
and prescriber_aoa_nb <>'' then
prescriber_id
when prescriber_dea_nb <>''
and prescriber_ama_nb <>'' then
prescriber_id
when prescriber_ama_nb <>''
and prescriber_aoa_nb <>'' then
prescriber_id
when prescriber_ama_nb <>'' then
prescriber_id
when prescriber_aoa_nb <>'' then
prescriber_id
else null
end as prescriber_id
from (select A.prescriber_id
, A.prescriber_dea_nb
, A.prescriber_ama_nb
, A.prescriber_aoa_nb
from claimsa.tprscbr_prescribe1 A
, prescriber_cross_ref B
where A.prescriber_id = B.prescriber_id
) temp1
) AS temp2
where temp2.prescriber_id is not null)

But, I am suspicious this will work. Because subselect may return
multiple rows.
I guess your intension is to correlate updating table
prescriber_cross_ref with claimsa.tprscbr_prescribe1.
Another point is that first three when conditions of a case expression
are included in last two when conditions.
THird point is you joined with prescriber_id. So, I thought you can
use EXISTS.
As a result, my idea is as follows:
update prescriber_cross_ref B
set preferred_in = 'Y'
where EXISTS
(select *
from (select case
when prescriber_ama_nb <>'' then
prescriber_id
when prescriber_aoa_nb <>'' then
prescriber_id
else null
end as prescriber_id
from claimsa.tprscbr_prescribe1 A
where A.prescriber_id = B.prescriber_id
) AS temp2
where temp2.prescriber_id is not null
)
Furthermore, this could produce same results.
update prescriber_cross_ref B
set preferred_in = 'Y'
where EXISTS
(select *
from claimsa.tprscbr_prescribe1 A
where A.prescriber_id = B.prescriber_id
AND (prescriber_ama_nb <>''
OR
prescriber_aoa_nb <>''
)
)
Nov 12 '05 #3
You can use IN predicate too.

update prescriber_cross_ref
set preferred_in = 'Y'
where prescriber_id IN
(select temp2.prescriber_id
from (select case
when prescriber_dea_nb <>''
and prescriber_ama_nb <>''
and prescriber_aoa_nb <>'' then
prescriber_id
when prescriber_dea_nb <>''
and prescriber_ama_nb <>'' then
prescriber_id
when prescriber_ama_nb <>''
and prescriber_aoa_nb <>'' then
prescriber_id
when prescriber_ama_nb <>'' then
prescriber_id
when prescriber_aoa_nb <>'' then
prescriber_id
else null
end as prescriber_id
from (select A.prescriber_id
, A.prescriber_dea_nb
, A.prescriber_ama_nb
, A.prescriber_aoa_nb
from claimsa.tprscbr_prescribe1 A
, prescriber_cross_ref B
where A.prescriber_id = B.prescriber_id
) temp1
) AS temp2
where temp2.prescriber_id is not null
)

You might realize that you do not need to specify "where
temp2.prescriber_id is not null".
Because NULL is not equal to any value(even with NULL).
But, it may be usefull to filter out unnecessary rows from subselect
and to make better performance.
OR

update prescriber_cross_ref
set preferred_in = 'Y'
where prescriber_id IN
(select A.prescriber_id
from claimsa.tprscbr_prescribe1 A
, prescriber_cross_ref B
where A.prescriber_id = B.prescriber_id
AND (A.prescriber_ama_nb <>''
OR
A.prescriber_aoa_nb <>''
)
)
Nov 12 '05 #4
> As a result, my idea is as follows:
update prescriber_cross_ref B
set preferred_in = 'Y'
where EXISTS
(select *
from (select case
when prescriber_ama_nb <>'' then
prescriber_id
when prescriber_aoa_nb <>'' then
prescriber_id
else null
end as prescriber_id
from claimsa.tprscbr_prescribe1 A
where A.prescriber_id = B.prescriber_id
) AS temp2
where temp2.prescriber_id is not null
)

This seems to be sql error. TABLE keyword is necessary.
update prescriber_cross_ref B
set preferred_in = 'Y'
where EXISTS
(select *
from TABLE
(select case
when prescriber_ama_nb <>'' then
prescriber_id
when prescriber_aoa_nb <>'' then
prescriber_id
else null
end as prescriber_id
from claimsa.tprscbr_prescribe1 A
where A.prescriber_id = B.prescriber_id
) AS temp2
where temp2.prescriber_id is not null
)
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: andrew | last post by:
Ok, pretty new to this php stuff, but good with perl/python etc. What is wrong with this php document ??? I get this error: Parse error: syntax error, unexpected $end in...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
3
by: Omar | last post by:
Hi, In the next sentence, what's wrong? <select name='id' onChange="window.location='dePaso.jsp?vuelta=a&nombre=id&anterior=ejecutivo = 'Daniel Perez'&valor='+this.options.value"> IE...
6
by: Daniel Rudy | last post by:
What is wrong with this program? When I try to compile it, I get the following error. Compiler is gcc on FreeBSD. strata:/home/dcrudy/c 1055 $$$ ->cc -g -oe6-3 e6-3.c e6-3.c: In function...
4
by: Nitin Bhardwaj | last post by:
Hello all, I am puzzled by the term 'semantics' ! Well I know about 'syntax of a language' - as defined by its associated grammar Then what is this semantics? What does the C Compiler checks...
9
by: Xiangliang Meng | last post by:
Hi, all. I see a very strange fragment code today. Uint32 enum { a = 100; b = 200; }; NOTE: Uint32 is defined to be 'unsigned' in other source files.
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
3
by: brianbasquille | last post by:
Hello all, Strange little problem here... am just trying to insert some basic information into an Access Database using OleDB. I'm getting a "Syntax error in Insert Into statement" when it...
5
by: Ryan | last post by:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder Creek","STATE":"CA","DIST":5745.4} I get an "invalid label" error... I'm kinda new to this. Thanks!
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.