SQL Server - What is the difference between inline selection and WHERE

Asked By Niels
19-Nov-09 08:02 AM
Hi,

I have a problem regarding inline selecting the right nodes from a tree.

I would really like to write my statement like the following

SELECT
@TreeXML = limitRequestTree.Item.query( '.' ),
@Identifier = limitRequestTree.Item.value( '@Identifier', 'varchar(18)' )
FROM @XmlDocument.nodes( 'TreeExtract/Tree[@Name=sql:variable("@TreeName")
and @State=sql:variable("@State")]' ) AS limitRequestTree(Item)

However sometimes this yields no results.

If I instead write the statement like this

SELECT
@TreeXML = limitRequestTree.Item.query( '.' ),
@Identifier = limitRequestTree.Item.value( '@Identifier', 'varchar(18)' )
FROM @XmlDocument.nodes( 'TreeExtract/Tree' ) AS limitRequestTree(Item)
WHERE limitRequestTree.Item.value( '@Name', 'varchar(18)' ) = @TreeName
AND limitRequestTree.Item.value( '@State', 'char(1)' ) = @State

Then the statement always gives the right results.

I think the first statment looks nicer and seems more like the right way to
do it. And according to the query analyser it should also be faster.
However I just do not understand why I dont get the same results in the first
statement as in the second. Can someone please help me understand.

Thanks
Varchar
(1)
XmlDocument.nodes
(1)
TreeXML
(1)
LimitRequestTree.Item.value
(1)
LimitRequestTree.Item.query
(1)
LimitRequestTree
(1)
XmlDocument
(1)
TreeName
(1)
  Martin Honnen replied to Niels
19-Nov-09 08:29 AM
Can you show us how you set the variables
@XmlDocument
@TreeName
@State
when you get different results from those two queries?


--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
  Niels replied to Niels
19-Nov-09 09:04 AM
Problem solved.... Comparing strings in XPath is case sensitive and in SQL it
is not.
Create New Account
help
Help SQL Server Hi Guys Declare @var varchar(200) SET @var = 'varchar1, varchar10, varchar15' But i want like this @var = varchar, varchar, varchar any one help on this thanks Rakesh SQL Server Programming Discussions Declare (1) Varchar (1) Bit (1) HiSS2005 (1) HiCan (1) OnlyCreate (1) Datatime (1) Rakesh (1) Hi Can you elaborate a little bit on? Hi Declare @var varchar(200) SET @var = 'Datetime15, Datetime1, varchar1, varchar10, varchar15, Numeric10, Numeric1' Above is the string type in @var I want to replace below like this Datetime, Datetime, varchar, varchar, varchar, Numeric, Numeric I want to remove the numeric part in @var Datatime instead of
procedure insert SQL Server What is wrong with this stored procedure: ALTER PROCEDURE SPDodavanjeFirme @FirmaNaziv varchar (100), @FirmaAdresa varchar (100), @FirmaPtt varchar (10), @FirmaMjesto varchar (100), @FirmaTelefon varchar (50), @FirmaFax varchar (50), @FirmaMob varchar (50), @FirmaMail varchar (100), @FirmaWeb varchar (100), @FirmaKontakt varchar (100), @FirmaOpis varchar (MAX) AS BEGIN SET NOCOUNT ON
Merge 2 tables SQL Server Hi all, I have 2 table: Create TableSource (ClientCode varchar, Field1 varchar, Field2 varchar) Create TableTarget(ClientCode varchar, Field1 varchar, Field2 varchar) I need to import in TableTarget every field in TableSource, for the same ClientCode, that Server 2005. Very thanks in advance. Luigi SQL Server Programming Discussions SQL Server 2005 (1) Varchar (1) Plamen.Luigi (1) CodiceCliente (1) TableTarget (1) TableSource (1) ClientCode (1) Here is one com keywords: Merge, 2, tables description: Hi all, I have 2 table: Create TableSource (ClientCode varchar, Field1 varchar, Field2 varchar) Create TableTarget(ClientCode varchar, Field1 varchar, F
actually insert the data from the xml file into the sql 2005 database: declare @xml varchar(max) declare @xmlHandle int - - Bulk load the xml from the file set @xml = ( select * from this select statement in your insert statement select * from openxml ( @xmlHandle , ' / Products / Product' ) with ( id varchar(32) '@Id' , [description] varchar(1024) 'Description' , url varchar(1024) 'Url' , caption varchar(1024) 'Caption' , captionnohtml varchar (1024) 'CaptionNoHTML' , code varchar(32) 'Code' , baseprice varchar (225) 'BasePrice' , salesprice varchar (225) 'SalesPrice' , categories varchar (225) 'Categories' , thumb varchar (1024) 'Thumb' , thumbheight