Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用另一个表中的信息更新表中的列_Sql_Sql Server_Sql Server 2012_Sql Server Express - Fatal编程技术网

Sql 使用另一个表中的信息更新表中的列

Sql 使用另一个表中的信息更新表中的列,sql,sql-server,sql-server-2012,sql-server-express,Sql,Sql Server,Sql Server 2012,Sql Server Express,我已经有了这个: 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] nva

我已经有了这个:

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]行

在更新时:

UPDATE [dbo].[PersonPhone]
SET [StartDate] = DATEADD(day, 1, [HumanResources].[EmployeeDepartmentHistory].[StartDate])
FROM [HumanResources].[EmployeeDepartmentHistory]
GO

SELECT row_number() over(order by (select 1)) AS [RN] FROM [HumanResources].[EmployeeDepartmentHistory]

SQL Server告诉我“此查询返回的结果不止一个…”现在写下,“不能调用datetime的方法”已经复制,但所有行都有一个值。如何逐行复制?如果是这样,如果我是你,我会将update查询放入循环语句中。