views:

110

answers:

2

I have a scalar UDF that I know to be deterministic, however SQL doesn't. Is there a way to declare it as deterministic so that I can then use it in a persisted computed column definition?

further clarification: The purpose of this exercise is that I need to harvest out specific values from an XML column on the row. I can't use the value method of the xml column in my computed column definition, but I can use it in a UDF. I know the xpath query in the value method will produce the same output give the same input so while I certainly understand that not all calls to value will be deterministic I want to assert that mine is.

A: 

As it turns out I needed to do was add WITH SCHEMABINDING to the UDF definition. the value method is determinisitic after all. (Apparently because the XQuery doesn't include dates?)

Ralph Shillington
A: 

Thank you for this answer! However, it does not seem to work when the function returns a datetime extracted from the XML. Have you observed this, or have any ideas how to solve it?

Thanks

edit: apparently the solution to this dilemna can be found here... http://stackoverflow.com/questions/246666/persisting-a-computed-datetime-column-in-sql-server-2005

Josh