Mega Code Archive

 
Categories / MSSQL Tutorial / XML
 

XPath query on XML

2>  CREATE TABLE dbo.Contacts 3> ( 4>   contactid       INT          NOT NULL PRIMARY KEY, 5>   contactname     NVARCHAR(50) NOT NULL, 6>   I18N        BIT          NOT NULL, 7>   otherattributes XML          NOT NULL 8> ); 9> GO 1> 2> INSERT INTO dbo.Contacts VALUES(1, N'Mike', 1, N'<I18N xmlns="I18N"><ID>0</ID><FL>Spanish</FL></I18N>'); 3> INSERT INTO dbo.Contacts VALUES(2, N'Her', 0, N'<Foreigns xmlns="Foreign"><NL>German</NL><ENG>1</ENG></Foreigns>'); 4> INSERT INTO dbo.Contacts VALUES(3, N'Ric', 1, N'<I18N xmlns="I18N"><ID>1</ID><FL>German</FL></I18N>'); 5> INSERT INTO dbo.Contacts VALUES(4, N'Gianluca', 0, N'<Foreigns xmlns="Foreign"><NL>Italian</NL><ENG>1</ENG></Foreigns>'); 6> GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) 1> 2> SELECT contactid, contactname, 3>   otherattributes.query(' 4~     declare namespace D="I18N"; 5~     /D:I18N/D:FL/text()') AS languagespoken 6> FROM dbo.Contacts 7> WHERE I18N = CAST(1 AS BIT); 8> GO Msg 1934, Level 16, State 1, Server J\SQLEXPRESS, Line 2 SELECT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or q uery notifications and/or xml data type methods. 1> 2> drop table dbo.Contacts;