Forum Discussion

ezpz97's avatar
ezpz97
Copper Contributor
Jan 12, 2026

Compat level 90: XML string-to-datetime UDF

Hello,

I’m testing a behavior described in SQL Server documentation for **database compatibility level 90**. The docs state that a user-defined function that converts an XML constant string value to a SQL Server date/time type is marked as **deterministic**.

On **SQL Server 2005**, I’m seeing the opposite: the function is marked as **non-deterministic** (`IsDeterministic = 0`). I’m trying to understand whether I’m missing a requirement/constraint or whether this is a doc mismatch / version-specific behavior.

### Environment
- Product: **Microsoft SQL Server 2005**
- Database compatibility level: **90**

---

## ✅ Repro script

```sql

IF OBJECT_ID('dbo.fn_ParamXmlToDatetime', 'FN') IS NOT NULL
    DROP FUNCTION dbo.fn_ParamXmlToDatetime;
GO

CREATE FUNCTION dbo.fn_ParamXmlToDatetime (@xml XML)
RETURNS DATETIME
WITH SCHEMABINDING
AS
BEGIN
    DECLARE @y DATETIME;

    -- Convert an XML value to DATETIME
    SET @y = CONVERT(DATETIME, @xml.value('(/r)[1]', 'datetime'));

    RETURN @y;
END
GO

SELECT
    OBJECTPROPERTY(OBJECT_ID('dbo.fn_ParamXmlToDatetime'), 'IsDeterministic') AS IsDeterministic,
    OBJECTPROPERTY(OBJECT_ID('dbo.fn_ParamXmlToDatetime'), 'IsPrecise')       AS IsPrecise;
GO
```

### Actual result
`IsDeterministic = 0` (non-deterministic)

### Expected result (based on docs)
`IsDeterministic = 1` (deterministic) for this pattern under compat level 90.

---

## Questions
1. Are there additional conditions required for SQL Server to mark this UDF as deterministic (for example, specific XQuery usage, avoiding `CONVERT`, using `CAST`, using `datetime2` doesn’t exist in 2005, etc.)?
2. Does the determinism rule apply only when converting from an **XML literal constant** inside the function, rather than an XML parameter value?
3. Is this behavior different for **typed XML** (XML schema collections) vs **untyped XML**?
4. Is this a known difference/bug in SQL Server 2005 where the UDF is functionally deterministic but still reported as non-deterministic by `OBJECTPROPERTY`?

Thank you for any clarification.

---

No RepliesBe the first to reply

Resources