Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 67067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:12:06+00:00 2026-05-10T19:12:06+00:00

I have an XML column in a table; I want to promote a certain

  • 0

I have an XML column in a table; I want to ‘promote’ a certain value in that XML as a computed column and index it for faster searching. I have a function that takes in the XML information and outputs the element of interest, like this:

CREATE FUNCTION [dbo].[fComputeValue] (@data XML) RETURNS datetime WITH SCHEMABINDING AS BEGIN   RETURN @data.value('(/Metadata/Value[@Key='StartDate'])[1]', 'datetime') END  

However when I try to create the computed column:

ALTER TABLE dbo.CustomMetadataTable ADD [StartDate] AS ([dbo].[fComputeValue]([CustomMetadataColumn])) PERSISTED 

I get the following error:

Msg 4936, Level 16, State 1, Line 2 Computed column ‘StartDate’ in table ‘CustomMetadataTable’ cannot be persisted because the column is non-deterministic.

It works if I:

  • work with varchar, int, double (i.e. other than datetime) values
  • remove the PERSISTED keyword (but then I can’t create an index on the column)

I should also mention that datetime values are in XSD datetime format. Any ideas? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:12:07+00:00Added an answer on May 10, 2026 at 7:12 pm

    What about:

    CREATE FUNCTION [dbo].[fComputeValue] (@data XML) RETURNS varchar(50) WITH SCHEMABINDING AS BEGIN   RETURN @data.value('(/Metadata/Value[@Key='StartDate'])[1]', 'varchar(50)') END 

    and:

    ALTER TABLE dbo.CustomMetadataTable ADD [StartDate] AS (convert(datetime,([dbo].[fComputeValue]([CustomMetadataColumn]), 127)) PERSISTED 

    or:

    return convert(datetime, @data.value('(/Metadata/Value[@Key='StartDate'])[1]', 'varchar(50)'), 127) 

    From books online:

    CONVERT is Deterministic unless one of these conditions exists:

    Source type is sql_variant.

    Target type is sql_variant and its source type is nondeterministic.

    Source or target type is datetime or smalldatetime, the other source or target type is a character string, and a nondeterministic style is specified. To be deterministic, the style parameter must be a constant. Additionally, styles less than or equal to 100 are nondeterministic, except for styles 20 and 21. Styles greater than 100 are deterministic, except for styles 106, 107, 109 and 113.

    It might help if you use CONVERT with style 127

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML in a column in my table: <keywords> <keyword name=First Name
I have a table Blah with a PK column BlahID and an XML column
I'm hand-coding Linq to SQL Entities and have a large XML column that I
I have XML column in my table which can contain XML like these 2
I have an XML column in one of my table. For example I have
I have a table create table Profiles (id int, xml_data xml ) that has
I'm trying to query a table which has a column that contains straight xml
Assuming I have a SQL Server 2005 table with an xml column containing the
I have an xml column and I want to persist a node count in
Let's say I have a column in a table where the datatype is XML.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.