I think this is a good question as it presents an interesting challenge of having an existing element without a text value. This is handled differently than simply adding a new element or replacing the contents of an existing one.
First, though, your provided XML was broken. If that is the XML you're receiving, you have other issues. For instance, in your original question, you had </AccountReference> which is invalid syntax by itself. I corrected this to <AccountReference /> both in your question as well as in my example.
With empty XML elements, you need to call the insert text DML of the XML.modify method.
DECLARE @xml XML =
'<document>
<StatusCode>ACV</StatusCode>
<PaymentMethodDetail>
<EFT>
<AccountNumber>123456789</AccountNumber>
<AccountName>ABCDEFGHIJK</AccountName>
</EFT>
</PaymentMethodDetail>
<PaymentExtendedData>
<CHECK>
<Source>System</Source>
<SourceType>ACH</SourceType>
</CHECK>
</PaymentExtendedData>
<PostMarkDate />
<EntryUserId>1</EntryUserId>
<Amount>0.00</Amount>
<EntryDate />
<PolicyLineOfBusiness>LOL</PolicyLineOfBusiness>
<PolicyReference />
<AccountReference />
<AccountId>2034001793</AccountId>
</document>';
DECLARE
@Amount DECIMAL(18,2) = 99.95,
@AccountReference VARCHAR(20) = '7657576875',
@PolicyReference VARCHAR(20) = '7657576567';
/* Update Amount */
SET @xml.modify('
replace value of (/document/Amount/text())[1]
with sql:variable("@Amount")
');
/* Insert the AccountReference text */
SET @xml.modify('
insert text {sql:variable("@AccountReference")} into (/document/AccountReference[1])[1]
');
/* Insert the PolicyReference text */
SET @xml.modify('
insert text {sql:variable("@PolicyReference")} into (/document/PolicyReference[1])[1]
');
/* Show updated XML */
SELECT @xml;
The updated XML is now:
<document>
<StatusCode>ACV</StatusCode>
<PaymentMethodDetail>
<EFT>
<AccountNumber>123456789</AccountNumber>
<AccountName>ABCDEFGHIJK</AccountName>
</EFT>
</PaymentMethodDetail>
<PaymentExtendedData>
<CHECK>
<Source>System</Source>
<SourceType>ACH</SourceType>
</CHECK>
</PaymentExtendedData>
<PostMarkDate />
<EntryUserId>1</EntryUserId>
<Amount>99.95</Amount>
<EntryDate />
<PolicyLineOfBusiness>LOL</PolicyLineOfBusiness>
<PolicyReference>7657576567</PolicyReference>
<AccountReference>7657576875</AccountReference>
<AccountId>2034001793</AccountId>
</document>
An example of updating a table:
DECLARE @xyz TABLE ( PaymentSearchId INT, XmlPayload XML );
INSERT INTO @xyz VALUES ( 18785,
'<document>
<StatusCode>ACV</StatusCode>
<PaymentMethodDetail>
<EFT>
<AccountNumber>123456789</AccountNumber>
<AccountName>ABCDEFGHIJK</AccountName>
</EFT>
</PaymentMethodDetail>
<PaymentExtendedData>
<CHECK>
<Source>System</Source>
<SourceType>ACH</SourceType>
</CHECK>
</PaymentExtendedData>
<PostMarkDate />
<EntryUserId>1</EntryUserId>
<Amount>0.00</Amount>
<EntryDate />
<PolicyLineOfBusiness>LOL</PolicyLineOfBusiness>
<PolicyReference />
<AccountReference />
<AccountId>2034001793</AccountId>
</document>' );
DECLARE
@PaymentSearchId INT = 18785,
@Amount DECIMAL(18,2) = 99.95,
@AccountReference VARCHAR(20) = '7657576875',
@PolicyReference VARCHAR(20) = '7657576567';
/* Update Amount */
UPDATE @xyz
SET XmlPayload.modify('
replace value of (/document/Amount/text())[1]
with sql:variable("@Amount")
')
WHERE PaymentSearchId = @PaymentSearchId;
/* Insert the AccountReference text */
UPDATE @xyz
SET XmlPayload.modify('
insert text {sql:variable("@AccountReference")} into (/document/AccountReference[1])[1]
')
WHERE PaymentSearchId = @PaymentSearchId;
/* Insert the PolicyReference text */
UPDATE @xyz
SET XmlPayload.modify('
insert text {sql:variable("@PolicyReference")} into (/document/PolicyReference[1])[1]
')
WHERE PaymentSearchId = @PaymentSearchId;
/* Show updated XML */
SELECT XmlPayload FROM @xyz WHERE PaymentSearchId = @PaymentSearchId;