ChrisRutherford
Programmer
Hi there,
I have a problem with populating a field in a table as there are a few records.
I have a table called Coverage. In there we have two fields, Policy_Number (varchar(20)) and Coverage_Number (varchar(10)). There could be up to four records per policy in this table. Currently the Policy_Number field is the only one populated, the Coverage_Number is set to Null.
Now what I need to do is the following...
Lets say I want to populate the coverage_number field with either 01, 02, 03 or 04 based on the policy number. I'm not sure how to do this. I start with a table looking like this...
Policy_Number Coverage_Number
123456 Null
123456 Null
... and I want something like this...
Policy_Number Coverage_Number
123456 01
123456 02
123456 03
In my table though there are many policies, some with just one entry and others with up to four entries. I can set the Coverage_Number field to '01' for those policies that have one entry easily enough using the following code...
update dbo.Coverage
set Coverage_Number = '01'
where Policy_Number in (select Policy_Number
from dbo.Coverage
group by Policy_Number
having count(*) = 1)
However any more than one entry per policy and I'm stuck. Any help would be much appreciated.
Kind regards,
Chris
I have a problem with populating a field in a table as there are a few records.
I have a table called Coverage. In there we have two fields, Policy_Number (varchar(20)) and Coverage_Number (varchar(10)). There could be up to four records per policy in this table. Currently the Policy_Number field is the only one populated, the Coverage_Number is set to Null.
Now what I need to do is the following...
Lets say I want to populate the coverage_number field with either 01, 02, 03 or 04 based on the policy number. I'm not sure how to do this. I start with a table looking like this...
Policy_Number Coverage_Number
123456 Null
123456 Null
... and I want something like this...
Policy_Number Coverage_Number
123456 01
123456 02
123456 03
In my table though there are many policies, some with just one entry and others with up to four entries. I can set the Coverage_Number field to '01' for those policies that have one entry easily enough using the following code...
update dbo.Coverage
set Coverage_Number = '01'
where Policy_Number in (select Policy_Number
from dbo.Coverage
group by Policy_Number
having count(*) = 1)
However any more than one entry per policy and I'm stuck. Any help would be much appreciated.
Kind regards,
Chris