I was helped out with this select query that I am using to get all tables with null values in two columns
select count(*)
from (
select LastModifiedDate from Table1
union all
select LastModifiedDate from Table2
union all
select LastModifiedDate from Table3
) a
where LastModifiedDate is null
To update all three tables is there a better way to do it then
Update table1
SET LastModifiedDate = GETDATE()
WHERE LastModifiedDate is null
Update table2
SET LastModifiedDate = GETDATE()
WHERE LastModifiedDate is null
and so on?
Sorry I split the query’s one looks for CreationDate and one looks for LastModifiedDate
Yes, there is a better way. As Gordon Linoff noted in the comments, you might overwrite valid created dates with your proposed query.
Try this instead:
Using
ISNULLwill preserve existingCreationDatedata. You don’t want to use it forLastModifiedDate, because you’re going to be modifying the rows, so that value should change.However, there’s no reason to try and restructure your statements, as there’s nothing wrong with them.