Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « SQL Advent 2012 Day 5: Do not trust the SSMS designersSQL Advent 2012 Day 4: Triggers, what to do, what not to do »
    comments

    I had to deploy a user defined function I was given yesterday, when I tried to I got the following error

    Msg 6850, Level 16, State 1, Procedure fnGetBooks, Line 8
    Column name 'TEXT()' contains an invalid XML identifier as required by FOR XML; '('(0x0028) is the first character at fault.

    The function looked a little like this one

    1. CREATE FUNCTION fnGetBooks (@AuthorID INT)
    2.  
    3. RETURNS VARCHAR(8000)
    4. AS
    5. BEGIN
    6.        
    7.  DECLARE @BookList VARCHAR(8000)
    8.  SELECT @BookList =(
    9.  
    10.      SELECT  BookName + ', ' AS [TEXT()]
    11.  
    12.      FROM    Books
    13.      WHERE AuthorID = @AuthorID
    14.      AND BookName IS NOT NULL
    15.      ORDER BY BookName
    16.  
    17.      FOR XML PATH('') )
    18.        
    19.  
    20. RETURN LEFT(@BookList,(LEN(@BookList) -1))
    21. END
    22. GO

    Trying to run that will give you the same error. Do you see the problem? First I determined what 0x0028 was, you can easy do this by running the following query

    1. SELECT CHAR(0x0028)

    As you can see, that is the left parentheses (
    Interesting but not really helpful, I know I wrote stuff that uses FOR XML PATH myself in the past. I ran the following query to give me a list of objects that use FOR XML PATH

    1. SELECT *
    2. FROM sys.objects
    3. WHERE OBJECT_DEFINITION(object_id) LIKE '%FOR%%XML%%PATH%'

    Then I looked at some of those functions, the only thing I noticed is that TEXT was lowercase

    Instead of

    1. SELECT  BookName + ', ' AS [TEXT()]

    It was

    1. SELECT  BookName + ', ' AS [text()]

    Once you make the change, the error will disappear. My suspicion is that some code formatting tool made it uppercase, perhaps the programmer copied and pasted it into some window and then packaged the output...I will have to follow up on that one

    If you are interested what that function is used for, take a look at Concatenate Values From Multiple Rows Into One Column

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    2189 views
    InstapaperVote on HN

    No feedback yet

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)