
Tricky Update statement need help please...
I would like to update the PersonId in #temp base on the
#source table (PersonId). Get the max value PersonId in
#Source and increment by 1 in #Temp table.
Please look at the result want below. Thanks in advance.
DROP TABLE #Source
GO
CREATE TABLE #Source
(
CustId INT NOT NULL,
PersonId INT NOT NULL,
PersonTpId INT NOT NULL,
PolicyId INT NULL
)
GO
INSERT #Source VALUES (15, 750, 3, 93187)
GO
SELECT *
FROM #Source
GO
CustId PersonId PersonTpId PolicyId
----------- ----------- ----------- -----------
15 750 3 93187
DROP TABLE #Temp
GO
CREATE TABLE #Temp
(
CustId INT NOT NULL,
PersonId INT NOT NULL,
PersonTpId INT NOT NULL,
PolicyId INT NULL
)
GO
INSERT #Temp VALUES (15, 15, 3, 85434)
INSERT #Temp VALUES (15, 16, 3, 51841)
INSERT #Temp VALUES (15, 17, 3, 13841)
INSERT #Temp VALUES (15, 18, 3, 81641)
INSERT #Temp VALUES (15, 19, 3, 23419)
INSERT #Temp VALUES (15, 20, 3, 93187)
GO
SELECT *
FROM #Temp
go
CustId PersonId PersonTpId PolicyId
----------- ----------- ----------- -----------
15 15 3 85434
15 16 3 51841
15 17 3 13841
15 18 3 81641
15 19 3 23419
15 20 3 93187
Result want:
-- Want to increment by 1 in PersonId.
CustId PersonId PersonTpId PolicyId
----------- ----------- ----------- -----------
15 756 3 85434
15 757 3 51841
15 758 3 13841
15 759 3 81641
15 760 3 23419
15 761 3 93187
Please ignore the text below.
Quote:
>-----Original Message-----
>Hi all,
>I have PersonId values and need to increment by 1. Any
>help would greatly appreciate.
>Example: 750 -> 751
> 751 -> 752
> ...
>Lam
>DROP TABLE #Temp
>GO
>CREATE TABLE #Temp
>(
> CustId INT NOT NULL,
> PersonId INT NOT NULL,
> PersonTpId INT NOT NULL,
> PolicyId INT NULL
>)
>GO
>INSERT #Temp VALUES (15, 750, 3, 85434)
>INSERT #Temp VALUES (15, 751, 3, 51841)
>INSERT #Temp VALUES (15, 752, 3, 13841)
>INSERT #Temp VALUES (15, 753, 3, 81641)
>INSERT #Temp VALUES (15, 754, 3, 23419)
>INSERT #Temp VALUES (15, 755, 3, 93187)
>GO
>SELECT *
> FROM #Temp
>go
>CustId PersonId PersonTpId PolicyId
>----------- ----------- ----------- -----------
>15 750 3 85434
>15 751 3 51841
>15 752 3 13841
>15 753 3 81641
>15 754 3 23419
>15 755 3 93187
>Result want:
>-- Want to increment by 1 in PersonId.
>CustId PersonId PersonTpId PolicyId
>----------- ----------- ----------- -----------
>15 756 3 85434
>15 757 3 51841
>15 758 3 13841
>15 759 3 81641
>15 760 3 23419
>15 761 3 93187
>.