473,387 Members | 1,295 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,387 software developers and data experts.

SQL - Update stmt

Uma
CREATE TABLE POL_HI_NBR (
POLICY_ID NUMERIC(15,0) NOT NULL,
UNITCOMMON_ID NUMERIC(15,0) NOT NULL,
HI_NBR_UNIQUE_CODE CHAR(10) NOT NULL,
HI_NBR_I INTEGER NOT NULL
);

CREATE TABLE POL_UNITCOMMON (
UNITCOMMON_ID NUMERIC(15,0) NOT NULL,
POLICY_ID NUMERIC(15,0) NOT NULL,
LOGICAL_ENTITY_ID INTEGER NOT NULL,
VERS_ORIG_MAJ_MIN INTEGER NOT NULL,
ROW_ACTIVE_STS_D INTEGER NOT NULL,
COMPANY_ID INTEGER NOT NULL,
PRODUCT_ID INTEGER NOT NULL,
PROGRAM_ID INTEGER NOT NULL,
PRIMARY_PRODUCT_F CHAR(1) NOT NULL,
UNIT_TYPE_C CHAR(10) NOT NULL,
UNIT_NBR_I INTEGER NOT NULL,
UNIT_TYPE_PROFILE CHAR(10),
NOTE_ATTACHED_F CHAR(1) NOT NULL,
ORIG_EFF_D INTEGER NOT NULL,
PARENT_UNITCOMMON NUMERIC(15,0),
PRIOR_UNTCOMMON_ID NUMERIC(15,0),
AMEND_NBR_1_2_I INTEGER NOT NULL
);
hI I got above 2 tables.Right now POL_HI_NBR.UNITCOMMON_ID containS
THE datafrom POL_UNITCOMMON.UNICOMMON_ID. Based upon some
POL_HI_NBR.HI_NBR_UNIQUE_CODE Condation , I have to update
POL_HI_NBR.UNITCOMMON_ID with POL_UNITCOMMON_PRODUCT_ID ??

i TRIED MANY WAYS .. no luck ..

UPDATE POL_HI_NBR Z
SET Z.UNITCOMMON_ID=
(SELECT A.PRODUCT_ID
FROM POL_UNITCOMMON AS A,
POL_HI_NBR AS B
WHERE A.POLICY_ID=B.POLICY_ID
AND A.UNITCOMMON_ID=B.UNITCOMMON_ID
AND B.POLICY_ID=Z.POLICY_ID
AND B.UNITCOMMON_ID=Z.UNITCOMMON_ID
AND B.HI_NBR_UNIQUE_CODE='CPU')
WHERE Z.UNITCOMMON_ID IN
(SELECT D.UNITCOMMON_ID
FROM POL_UNITCOMMON AS D,
POL_HI_NBR AS E
WHERE D.POLICY_ID=E.POLICY_ID
AND D.UNITCOMMON_ID=E.UNITCOMMON_ID
AND E.POLICY_ID=Z.POLICY_ID
AND E.UNITCOMMON_ID=Z.UNITCOMMON_ID
AND E.HI_NBR_UNIQUE_CODE='CPU')

any ideas..

Thanks
Uma
Nov 12 '05 #1
1 4636
Hi Uma,
i TRIED MANY WAYS .. no luck ..

UPDATE POL_HI_NBR Z
SET Z.UNITCOMMON_ID=
(SELECT A.PRODUCT_ID
FROM POL_UNITCOMMON AS A,
POL_HI_NBR AS B
WHERE A.POLICY_ID=B.POLICY_ID
AND A.UNITCOMMON_ID=B.UNITCOMMON_ID
AND B.POLICY_ID=Z.POLICY_ID
AND B.UNITCOMMON_ID=Z.UNITCOMMON_ID
AND B.HI_NBR_UNIQUE_CODE='CPU')
WHERE Z.UNITCOMMON_ID IN
(SELECT D.UNITCOMMON_ID
FROM POL_UNITCOMMON AS D,
POL_HI_NBR AS E
WHERE D.POLICY_ID=E.POLICY_ID
AND D.UNITCOMMON_ID=E.UNITCOMMON_ID
AND E.POLICY_ID=Z.POLICY_ID
AND E.UNITCOMMON_ID=Z.UNITCOMMON_ID
AND E.HI_NBR_UNIQUE_CODE='CPU')

any ideas..

Try the following:

UPDATE POL_HI_NBR Z
SET Z.UNITCOMMON_ID= (SELECT A.PRODUCT_ID
FROM POL_UNITCOMMON AS A
WHERE A.POLICY_ID= Z.POLICY_ID
AND A.UNITCOMMON_ID= Z.UNITCOMMON_ID)
WHERE Z.HI_NBR_UNIQUE_CODE='CPU'
AND Z.UNITCOMMON_ID IN (SELECT D.UNITCOMMON_ID
FROM POL_UNITCOMMON AS D
WHERE D.POLICY_ID= Z.POLICY_ID);

or

UPDATE POL_HI_NBR Z
SET Z.UNITCOMMON_ID= (SELECT A.PRODUCT_ID
FROM POL_UNITCOMMON AS A
WHERE A.POLICY_ID= Z.POLICY_ID
AND A.UNITCOMMON_ID= Z.UNITCOMMON_ID)
WHERE Z.HI_NBR_UNIQUE_CODE='CPU'
AND EXISTS (SELECT *
FROM POL_UNITCOMMON AS D
WHERE D.POLICY_ID= Z.POLICY_ID
AND D.UNITCOMMON_ID= Z.UNITCOMMON_ID);
The idea is you need to join A to Z. Not A to a different version of
POL_HI_NBR (B above). This query will only work if there is a one to
one relationship between POL_UNITCOMMON and POL_HI_NBR (on policy_id
and unitcommon_id).

Christian.
Nov 12 '05 #2

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

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
14
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The...
7
by: Jean-Marc Blaise | last post by:
Hi, The dev center calls sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj') to update the sqlj routine source. I tried in CLP from the directory containing jar and sqlj files (Windows...
2
by: claus.hirth | last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement in order to play with the PREPARE and EXECUTE keywords. In transcript 1 below the call to that stored procedure does not...
3
by: Jay | last post by:
Hello, I need to use Update Sql stmt from my page. Some of the field values has apostrophes and and quotes. How do I make ado.net ignore those characters? Eg- UPDATE ROOM SET HEIGHT='3'...
1
by: komatouch09 | last post by:
Hi I am new to visual basic. I write program to navigate & update data from table. My database is in Informix & use ODBC connection. When I nevigate the data it works properly. When I Update the...
0
by: David Linsin | last post by:
I created a simple test case to reproduce the problem (also check Bug #15500): import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;...
3
by: annecarterfredi | last post by:
I have two tables...Table1(name, date); Table2(appointment_name, name, appointment_date). I want to update appointment_date in Table2 with date from Table1 (business requirement). I am trying to...
6
by: pradeep84 | last post by:
Hi to all... in the following code... i hav problem in the update.. it is updating upto qty and it is not updating value.. it shows error like syntax error in the update statement.... help me to...
5
by: Yew12 | last post by:
I have been trying to update the details in a access database but, all I get is a white screen and all the errors I have built-in give me no help at all. All help is greatly appreciated. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.