Это довольно интересно. Я могу воспроизвести его с помощью Access 2010, SQL Server 2008 R2, ODBC Driver 17 для SQL Server.
Но только , если столбец (N) VARCHAR включен в запрос UPDATE
!
UPDATE AAA SET Smallint2 = Smallint1, Int2 = Int1;
работает.
CREATE TABLE AAA (
ID int IDENTITY(1,1) NOT NULL,
Smallint1 SMALLINT NULL,
Smallint2 SMALLINT NULL,
Int1 INT NULL,
Int2 INT NULL,
foo NVARCHAR(255) NULL,
RV TIMESTAMP NOT NULL,
CONSTRAINT PK_AAA PRIMARY KEY (ID)
)
GO
INSERT AAA (Smallint1, Smallint2, Int1, Int2, foo)
VALUES (1, 0, 77, 9999, 'asdf'),
(3456, NULL, NULL, 1234, 'null')
Access-VBA:
Sub TestAAA()
Dim strSql As String
strSql = "UPDATE AAA SET Smallint2 = Smallint1, Int2 = Int1;"
CurrentDb.Execute strSql, dbFailOnError + dbSeeChanges
Stop
' Requery table => UPDATE was successful!
' Edit and save values in Smallint1 / Int1
strSql = "UPDATE AAA SET Smallint2 = Smallint1, Int2 = Int1, foo = 'with NVARCHAR';"
CurrentDb.Execute strSql, dbFailOnError + dbSeeChanges
Stop
' Requery => Smallint2 / Int2 are not updated, "foo" is!
strSql = "UPDATE AAA SET Smallint2 = CInt(Smallint1), Int2 = CLng(Int1), foo = 'with Conversion';"
CurrentDb.Execute strSql, dbFailOnError + dbSeeChanges
' Requery => Smallint2 / Int2 are updated!
End Sub
Результаты:
- исходное состояние
- после первого обновления
- после ручного редактирования и второго обновления
- после третьего обновления
+----+-----------+-----------+-----------+-----------+-----------------+
| ID | Smallint1 | Smallint2 | Int1 | Int2 | foo |
+----+-----------+-----------+-----------+-----------+-----------------+
| 1 | 1 | 0 | 77 | 9999 | asdf |
| 2 | 3456 | | | 1234 | null |
| | | | | | |
| ID | Smallint1 | Smallint2 | Int1 | Int2 | foo |
| 1 | 1 | 1 | 77 | 77 | asdf |
| 2 | 3456 | 3456 | | | null |
| | | | | | |
| ID | Smallint1 | Smallint2 | Int1 | Int2 | foo |
| 1 | 222 | 1 | 988888888 | 77 | with NVARCHAR |
| 2 | 333 | 3456 | 999999999 | | with NVARCHAR |
| | | | | | |
| ID | Smallint1 | Smallint2 | Int1 | Int2 | foo |
| 1 | 222 | 222 | 988888888 | 988888888 | with Conversion |
| 2 | 333 | 333 | 999999999 | 999999999 | with Conversion |
+----+-----------+-----------+-----------+-----------+-----------------+