XML Query treating alias as DB

  • Running this:

    INSERT INTO [dbo].RichTest

    SELECT doc.col.value('(.)[1]', 'nvarchar(50)')

    FROM @RichTests.nodes('/macs/mac') AS doc(col)

    WHERE NOT EXISTS (SELECT 1 FROM [RichTest] WHERE [Name] = doc.col.value('(.)[1]', 'nvarchar(50)')

    Getting this:

    System.Data.SqlClient.SqlException: Database 'Doc' cannot be opened because it is offline.

    Notes:

    When this is run in SSMS, it fails with DB 'Doc' error outlined above

    Select @@version gives

    Microsoft SQL Server 2008 (SP3) - 10.0.5538.0 (X64)

  • richard.wanamaker (11/24/2016)


    Running this:

    INSERT INTO [dbo].RichTest

    SELECT doc.col.value('(.)[1]', 'nvarchar(50)')

    FROM @RichTests.nodes('/macs/mac') AS doc(col)

    WHERE NOT EXISTS (SELECT 1 FROM [RichTest] WHERE [Name] = doc.col.value('(.)[1]', 'nvarchar(50)')

    Getting this:

    System.Data.SqlClient.SqlException: Database 'Doc' cannot be opened because it is offline.

    Notes:

    When this is run in SSMS, it fails with DB 'Doc' error outlined above

    Select @@version gives

    Microsoft SQL Server 2008 (SP3) - 10.0.5538.0 (X64)

    What do you get when you run this query?

    😎

    SELECT

    SDB.name

    FROM sys.databases SDB

    WHERE SDB.NAME = N'Doc';

  • He he, didn't read the post properly:w00t:

    😎

    Can you post an example of the XML stored in the @RichTests variable?

  • It is a passed in xml variable:

    @RichTest xml=null

  • Additional info:

    This is failing just on the creation of the Stored Procedure and works in all other implementations for SS (various versions from 2005 through 2014)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply