SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query for XML column values comparison


Query for XML column values comparison

Author
Message
IT researcher
 IT researcher
Mr or Mrs. 500
Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)

Group: General Forum Members
Points: 592 Visits: 1798
Hi
We have a query for return rows by comparing with XML column values


SELECT [DBChanges].* FROM [Checklists].dbo.[DBChanges] WHERE ( [Permited_by].exist('for $x in /Root/Row where ( fn:upper-case($x/User[1]) = fn:upper-case("shw") or fn:upper-case($x/User[1]) = fn:upper-case("skt") or fn:upper-case($x/User[1]) = fn:upper-case("prs") ) return $x')>0 )


It seems we cant use IN in Xquery. So we ended up with using OR conditions for matching many values for a row.
Is there anything to optimize in the query?
Mark Cowne
Mark Cowne
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3129 Visits: 24107
Try this


WHERE  [Permited_by].exist('/Root/Row/User/.[fn:upper-case(.)= ("SHW","SKT","PRS")]')>0 



____________________________________________________

Deja View - The strange feeling that somewhere, sometime you've optimised this query before

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537




IT researcher
 IT researcher
Mr or Mrs. 500
Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)

Group: General Forum Members
Points: 592 Visits: 1798
Thanks for reply
"SELECT [DBChanges].* FROM [Checklists].dbo.[DBChanges] WHERE [Permited_by].exist('/Root/Row/User/.[fn:upper-case(.)= ("SHW","SKT","PRS")]')>0" will work very well
But then I thought i should use IN in query.After searching sometimes i found this query
select *
from [Checklists].dbo.[DBChanges]
where [Permited_by].value('(Root/Row/User)[1]', 'varchar(50)') IN ('Shw','skt','prs')


But this query will match with user only in first row because of using '(Root/Row/User)[1]'.How can i madify this to match with whole XML row?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search