Hello. I am trying to check if a table definition (the default value on a constraint) is equal to UTC Time by using the following query:

IF NOT EXISTS((SELECT object_definition(default_object_id) AS definition
FROM sys.columns
WHERE name = 'ModifiedDate'
AND object_id = object_id('dbo.WorkflowAudit')) == GETUTCDATE())

However, you can not compare a function (GETUTCDATE()) to this Select Statement. I need to do it this way because I am building an update script and it can only update the table IF the table definition is NOT equal to UTC TIME Any ideas? Thank you

One thing that I tried to do is to get the constraint and see if the constraint is equal to "(getutcdate())". Here is the code for this:

SELECT object_definition(default_object_id) AS definition
                        FROM sys.columns
                        WHERE name = 'ModifiedDate'
                        AND object_id = object_id('dbo.WorkflowAudit') == '(getutcdate())'

Basically, if the column default is "(getutcdate())", it should match the string "(getutcdate())". This may be an impractical way of doing it but this is all I could think of.

Have you tried getting the date first?
ie. the first line reads getutcdate() and that is assigned to a variable
then follow that with the select, assign the query result to a second variable, and compare that to the first variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.