Here I need to add an Alias name to 'TableName' AS T. The Update already have a 'From' statement for getting value 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
Try this,
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