Let's say I have a table that has columns Name, Date, StoredProcedure
in SQL Server 2016
I need to query this table and loop through the stored procedure column and check to see if this stored procedure exists in the database. If it doesn't exist, then I need to make this row null for the stored procedure column only.
This is what I tried but it doesn't work
Select m1.StoredProcedure
from MyTable m1
where
IF NOT EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'StoredProcedure')
AND type IN (N'P', N'PC'))
Then Update MyTable m2
Set StoredProcedure = ''
Where m2 StoredProcedure = m1.StoredProcedure