0

私はすでにこれを持っています:

USE [AdventureWorks2012];
--- somewhere create table  
IF OBJECT_ID('[dbo].[PersonPhone]','U') IS NOT NULL   
DROP TABLE [dbo].[PersonPhone]  
CREATE TABLE [dbo].[PersonPhone](  
    [BusinessEntityID] [int] NOT NULL,  
    [PhoneNumber] nvarchar(25) NOT NULL,  
    [PhoneNumberTypeID] [int] NOT NULL,  
    [ModifiedDate] [datetime] NOT NULL)  
--- and append new column  
ALTER Table [dbo].[PersonPhone]  
ADD [StartDate] date NULL  
--- after this, i want copy dates in this column (at another table, we increase dates by one)  
UPDATE [dbo].[PersonPhone]
SET [StartDate] = [NewTable].[NewDate]
FROM (
       SELECT DATEADD(day, 1, [HumanResources].[EmployeeDepartmentHistory].[StartDate]) AS [NewDate],
          row_number() over(order by (select 1)) AS [RN]
   FROM [HumanResources].[EmployeeDepartmentHistory]
 ) [NewTable]

[NewTable] から [dbo].[PersonPhone].[StartDate] 行に値をコピーするクエリを改善するにはどうすればよいですか?

4

1 に答える 1