Question : filter nodes with xquery

HI All,

I have an xml field with the following contents:

 
   
   
 

 
    hohohoho
 



How do I query that field to exclude nodes with a cultureName attribute other than 'en-GB'. Nodex without a cultureName attribute should stay included so the results should be this:

 
   
 

 
    hohohoho
 

Answer : filter nodes with xquery

I dont think u can perform 'Select' and 'Modify' at the same time. It's like executing Update query in a select statement. However here's a work arround tht i have got for u. see if fits the bill. I created a dummy test table to give u a clear idea. All the scripts are included in the code below.
Cheers,
Amit
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
/***************************Test Table Creation************************/
CREATE TABLE [dbo].[TestTable](
	[RowID] [int] IDENTITY(1,1) NOT NULL,
	[RowName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Data] [xml] NULL,
 CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED 
(
	[RowID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
/*********************************************************************/
/***************************Insert Values*****************************/
Declare @Request As XML
Set @Request = '

	
		
		
		
		
		
	
	
		hohohoho
	

'
Insert	Into TestTable
		(
			RowName
			,Data
		)
Values	(
			'Row 1 Data'
			,@Request
		)

Set @Request = '

	
		
		
		
		
	
	
		hohohoho
	

'
Insert	Into TestTable
		(
			RowName
			,Data
		)
Values	(
			'Row 2 Data'
			,@Request
		)

Set @Request = '

	
		
		
		
	
	
		hohohoho
	

'
Insert	Into TestTable
		(
			RowName
			,Data
		)
Values	(
			'Row 3 Data'
			,@Request
		)
/*********************************************************************/
/***************************Select Logic *****************************/

/*Dont perform 'modify' in the select statement. Instead get the whole xml in a variable and the do the 'modify' thingy*/
Set @Request = (
			Select	RowID
					,RowName
					,Data
			From	TestTable
			For		XML Auto,Root('RootData')
		)

Set	@Request.modify('delete (//Properties/Cultures/Culture[@cultureName != "en-GB"])')

/*Get the data in XML format*/
Select	@Request

/*Get the data in tabular format*/
Select	A.B.value('@RowID', 'Int') As RowID
		,A.B.value('@RowName', 'Varchar(50)')
		,A.B.query('*')
From	@Request.nodes('//RootData/TestTable') A(B)
/*********************************************************************/
Random Solutions  
 
programming4us programming4us