Avatar of bsumanrao
bsumanrao
 asked on

MS SQL SERVER 2005

I had one table named Policy_Rpt.ILRCL in a database. There is also related procedure to this table named Policy_Rpt.usp_ILRCL.

Generally the table is populated by the procedure.

Now I created One more table named Policy_rpt.Ageny with an extra column called 'Lossdesc' with initial value Null in all the columns..  

I populated this table using the following command.

Insert into Policy_rpt.Ageny (columns........) Select * from Policy_Rpt.ILRCL.

Now i need to add the following functionality for the new column 'Loss desc'. How can i do it...

(      
LossDesc  (ClaimNumber level  one record for claim)

From Kaimart_Rpt.ILRCL.ClaimNumber = Kaimart.LossDescription.ClaimNumber

Use column LossDescription in Kaimart.LossDescription

* One value for all rows on a Claim
)
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
bsumanrao

8/22/2022 - Mon
reb73

For populating LossDesc during insert of new records use -

INSERT Policy_rpt.Ageny
SELECT  I.*
      ,LossDesc = (SELECT MAX(KR.LossDescription) FROM Kaimart_Rpt.ILRCL WHERE ClaimNumber = PR.ClaimNumber)
FROM
      Policy_Rpt.ILRCL PR

For updating NULL values for existing records use -

UPDATE
      Policy_rpt.Ageny
SET
      LossDesc = (SELECT MAX(KR.LossDescription) FROM Kaimart_Rpt.ILRCL WHERE ClaimNumber = PR.ClaimNumber)
reb73

Actually the second statement should be as follows -

UPDATE
      PA
SET
      LossDesc = (SELECT MAX(KR.LossDescription) FROM Kaimart_Rpt.ILRCL WHERE ClaimNumber = PA.ClaimNumber)
FROM
      Policy_rpt.Ageny PA
bsumanrao

ASKER
Hi reb,

Sorry for mistake in the Question...

There is only 2 Databases..Policy & Policy_Rpt.
There is no Kaimart & Kaimart_rpt...

Again i am pasting the criteria here, Please go through it & modify the solution for me .... Please....

LossDesc  (ClaimNumber level  one record for claim)

From Policy_Rpt.ILRCL.ClaimNumber = Policy.LossDescription.ClaimNumber

Use column LossDescription in Policy.LossDescription

* One value for all rows on a Claim
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
reb73

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bsumanrao

ASKER
Iam sorry reb,

If i try to insert, Iam getting following errors...........

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "KA.ClaimNumber" could not be bound.
Msg 213, Level 16, State 1, Line 1
Insert Error: Column name or number of supplied values does not match table definition.