如何从 XML 使用 Table 别名写入 SQL Server 2008 中的 UPDATE 已经有一个 'From' 语句

How to write UPDATE from XML with Table Alias in SQL Server 2008 already have a 'From' statement

这里我需要为 'TableName' AS T 添加一个别名。更新已经有一个 'From' 语句用于从 XML.

获取值
UPDATE TableName SET 
  TableName.PrintedBy = ISNULL(TableName.PrintedBy,der.PrintedBy), 
  TableName.PrintedDate = ISNULL(TableName.PrintedDate,GETDATE()),
  @RetVal=der.NoteId 
FROM (     
SELECT PrintedBy,NoteId
      FROM OPENXML(@hDoc1,'TableName',1)
      WITH   (  PrintedBy INT 'PrintedBy', 
                NoteId INT 'NoteId'
             )
    ) as der
WHERE TableName.NoteId = der.NoteId 

试试这个,

UPDATE T SET 
T.PrintedBy = ISNULL(T.PrintedBy,der.PrintedBy), 
T.PrintedDate = ISNULL(T.PrintedDate,GETDATE()),
@RetVal=der.NoteId 
FROM (     
    SELECT PrintedBy,NoteId
    FROM OPENXML(@hDoc1,'TableName',1)
    WITH   (  PrintedBy INT 'PrintedBy', 
              NoteId INT 'NoteId'
            )
     ) as der, TableName T
WHERE T.NoteId = der.NoteId