NewbieWithSQL
Programmer
Here is the scenario that I have. I have a table "UpdateTest" (DDL at the end) that contains a few records.
UpdateID Data
-------------------
1 One
2 Two
3 Three
In another table "UpdateDelta" (DDL at the end), there are several records
UpdateDeltaID DeltaData UpdateDelta RowID
-----------------------------------------------
1 OneA U 1
2 TwoA I 2
NULL Four I 3
NULL Five I 4
NULL Six I 5
2 OneB U 6
I need to be able to process all three records that have a "U" in UpdateDelta into UpdateTest. When I run the update command it only shows updating 2 rows, when in it should update 3 rows. It only processes the first "U" record with UpdateDeltaID of 1.
This is the update statement that I'm using
update ut
set Data = ud.DeltaData
from UpdateTest ut
inner join UpdateDelta ud on ud.UpdateDeltaID = ut.UpdateID
where ud.UpdateDelta = 'U'
My results are
UpdateID Data
---------------------
1 OneA
2 TwoA
Results should be
UpdateID Data
---------------------
1 OneB
2 TwoA
I need to process the records in the order that they are in, which is why there is a rowid field, which is coming from the import process.
Any help is this matter is greatly appreciated.
-------------- DDL ------------
UpdateTest table DDL
CREATE TABLE [dbo].[UpdateTest](
[UpdateID] [int] NOT NULL,
[Data] [varchar](10) NOT NULL,
CONSTRAINT [PK_UpdateTest] PRIMARY KEY CLUSTERED
(
[UpdateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
--- Insert data into UpdateTest
insert into UpdateTest(Data)
values('One')
insert into UpdateTest(Data)
values('Two')
insert into UpdateTest(Data)
values('Three')
CREATE TABLE [dbo].[UpdateDelta](
[UpdateDeltaID] [int] NULL,
[DeltaData] [varchar](10) NOT NULL,
[UpdateDelta] [char](1) NOT NULL,
[RowID] int identity(1,1) not null
) ON [PRIMARY]
Go
--- Insert of data into UpdateDelta
insert into UpdateDelta (UpdateDeltaID, DeltaData, UpdateDelta)
values (1,'OneA','U')
insert into UpdateDelta (UpdateDeltaID, DeltaData, UpdateDelta)
values (1,'OneB','U')
insert into UpdateDelta (UpdateDeltaID, DeltaData, UpdateDelta)
values (2,'TwoA','U')
insert into UpdateDelta (DeltaData, UpdateDelta)
values ('Four','I')
insert into UpdateDelta (DeltaData, UpdateDelta)
values ('Five','I')
insert into UpdateDelta (DeltaData, UpdateDelta)
values ('Six','I')
UpdateID Data
-------------------
1 One
2 Two
3 Three
In another table "UpdateDelta" (DDL at the end), there are several records
UpdateDeltaID DeltaData UpdateDelta RowID
-----------------------------------------------
1 OneA U 1
2 TwoA I 2
NULL Four I 3
NULL Five I 4
NULL Six I 5
2 OneB U 6
I need to be able to process all three records that have a "U" in UpdateDelta into UpdateTest. When I run the update command it only shows updating 2 rows, when in it should update 3 rows. It only processes the first "U" record with UpdateDeltaID of 1.
This is the update statement that I'm using
update ut
set Data = ud.DeltaData
from UpdateTest ut
inner join UpdateDelta ud on ud.UpdateDeltaID = ut.UpdateID
where ud.UpdateDelta = 'U'
My results are
UpdateID Data
---------------------
1 OneA
2 TwoA
Results should be
UpdateID Data
---------------------
1 OneB
2 TwoA
I need to process the records in the order that they are in, which is why there is a rowid field, which is coming from the import process.
Any help is this matter is greatly appreciated.
-------------- DDL ------------
UpdateTest table DDL
CREATE TABLE [dbo].[UpdateTest](
[UpdateID] [int] NOT NULL,
[Data] [varchar](10) NOT NULL,
CONSTRAINT [PK_UpdateTest] PRIMARY KEY CLUSTERED
(
[UpdateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
--- Insert data into UpdateTest
insert into UpdateTest(Data)
values('One')
insert into UpdateTest(Data)
values('Two')
insert into UpdateTest(Data)
values('Three')
CREATE TABLE [dbo].[UpdateDelta](
[UpdateDeltaID] [int] NULL,
[DeltaData] [varchar](10) NOT NULL,
[UpdateDelta] [char](1) NOT NULL,
[RowID] int identity(1,1) not null
) ON [PRIMARY]
Go
--- Insert of data into UpdateDelta
insert into UpdateDelta (UpdateDeltaID, DeltaData, UpdateDelta)
values (1,'OneA','U')
insert into UpdateDelta (UpdateDeltaID, DeltaData, UpdateDelta)
values (1,'OneB','U')
insert into UpdateDelta (UpdateDeltaID, DeltaData, UpdateDelta)
values (2,'TwoA','U')
insert into UpdateDelta (DeltaData, UpdateDelta)
values ('Four','I')
insert into UpdateDelta (DeltaData, UpdateDelta)
values ('Five','I')
insert into UpdateDelta (DeltaData, UpdateDelta)
values ('Six','I')