Further to the OP comment above... try replacing
set @xml= (select CAST((
selecT DBName as 'td', '',
FullBackup_date as 'td', '',
LogBackupDate as 'td'
FROM final_table where LogBackupDate < (convert (datetime, (dateadd(hour,-2,getdate())),121))
for xml path ('tr'),elements) as nvarchar(max) )
)
with
set @xml= (select CAST((
select DBName as 'td', '',
FORMAT(FullBackup_date, 'yyyyMMdd HHmmss') as 'td', '',
FORMAT(LogBackupDate, 'yyyyMMdd HHmmss') as 'td'
FROM final_table where LogBackupDate < dateadd(hour,-2,getdate())
for xml path ('tr'),elements) as nvarchar(max) )
)
Points to note - you've stated that you are using a
datetime
type so get rid of the conversion of a
datetime
to a
varchar
in the
WHERE
statement
If you don't want the date in that specific format try using one of the standard formats - see this list
SQL Server Date Format Cheatsheet | TablePlus[
^]
Given that this is an email for a human rather than for a system your users might prefer something like format 113 e.g.
SELECT CONVERT(VARCHAR(26), GETDATE(), 113)
displays as
10 Apr 2019 15:21:50:670