Bug in SQL Server 2000 with OPENXML?

Hi,

I am trying to make some stored procedures that take in lists of well sites and well ids and find the wells in the sites except for those in the list of well ids.

I have a stored procedure like this.


ALTER procedure sp_wellSelect (@criteria ntext)
as

DECLARE @hDoc int
--Prepare input values as an XML documnet
exec sp_xml_preparedocument @hDoc OUTPUT, @criteria
--Select data from the table based on values in XML
SELECT distinct w.well_id, w.well_name
FROM Wells_by_site ws
INNER JOIN well w
ON ws.well_id = w.well_id
WHERE ws.SITE_ID IN (
SELECT sid
FROM OPENXML (@hdoc, '/D/C/S', 1)
WITH (sid int)
) AND
w.WELL_ID NOT IN (
SELECT wid
FROM OPENXML (@hdoc, '/D/C/W', 1)
WITH (wid varchar(15))
)
ORDER BY w.well_name
EXEC sp_xml_removedocument @hDoc
GO

When I run this though it DOES NOT exclude the wells in the list of well ids. Here is an example.


-- Get all wells in site 80 except for 'A7793'
sp_wellSelect '<D><C><S sid="80"/><W wid="A7793"/></C></D>'

well_id well_name
A7793 299-W21-51
A7858 299-W22-51
B8552 299-W22-79
A7833 299-W22-8
A9901 699-36-70A

(5 row(s) affected)

I can run a query which is equivalent to the stored procedure and this one will exclude the well as expected.


SELECT distinct w.well_id, w.well_name
FROM Wells_by_site ws
INNER JOIN well w
ON ws.well_id = w.well_id
WHERE ws.site_id IN (80)
AND
w.well_id NOT IN ('A7793')
ORDER BY w.well_name


well_id well_name
A7858 299-W22-51
B8552 299-W22-79
A7833 299-W22-8
A9901 699-36-70A

(4 row(s) affected)

Another strange thing is that if I don't do a SELECT DISTINCT in the stored procedure, it does exclude the 'A7793'

I have just removed the DISTINCT and saved the stored procedure. Now I run it again.


sp_wellSelect '<D><C><S sid="80"/><W wid="A7793"/></C></D>'

well_id well_name
A7858 299-W22-51
B8552 299-W22-79
A7833 299-W22-8
A9901 699-36-70A

(4 row(s) affected)

How can the same query give different results? Could this be a bug in SQL server with OPENXML? It makes no sense to me?

Thanks in advance

[2401 byte] By [SumantGupta] at [2008-2-6]
# 1
Hi Sumant, I was trying to repro your experience with SQL Server 2005 and got the correct result (by using the sample data in your example):

A7858 299-W22-51
B8552 299-W22-79
A7833 299-W22-8
A9901 699-36-70A

What version of SQL Server do you use and how does your database schema and data look like?

Best regards
Michael

MRys at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...
# 2
Sumant,

This is a known issue that was fixed in SP4. Please upgrade to SP4.

Thanks,
Galex Yen

GalexYen at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...
# 3
I am using MSDE from my home computer and got MSDE SP4, but it refuses to install - it says "The instance name specified is invalid"

How do I upgrade the default instance?

SumantGupta at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...
# 4

Do you have other SQL Server instances running on the same machine?

Michael

MRys at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...
# 5
MSSQLSERVER is the only one

I carefully looked through the read me and got the installer to run successfully with

setup /upgradesp sqlrun SECURITYMODE=SQL UPGRADEUSER=sa /L*v C:\MSDELog.log

It showed the setup dialog and everything, but it STILL has not upgraded, even though the setup ran, because when I do a

select @@version

I still get Service Pack 2

--

NEVER MIND! It worked.

They really like to confuse you, don't they.

I see Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)
May 3 2005 23:18:38
Copyright (c) 1988-2003 Microsoft Corporation
Desktop Engine on Windows NT 5.1 (Build 2600: Service Pack 2)

The 8.00.2039 is service pack 4, and the OPENXML now works OK, so the rest of the version information (Build 2600: Service Pack 2) seems to be a lie.

Thank you all for the help.

SumantGupta at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...
# 6

Good to hear this. The Build 2600: Service Pack 2

refers to the operating system service pack :-).

Best regards

Michael

style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

<Sumant href="mailto:Gupta@discussions.microsoft.com">Gupta@discussions.microsoft.com>

wrote in message href="news:06026cb6-b27e-4c37-8a6f-1ff40f1e38a5_WBRev1_@discussions.microsoft.com">news:06026cb6-b27e-4c37-8a6f-1ff40f1e38a5_WBRev1_@discussions..microsoft.com...

This

post has been edited either by the author or a moderator in the Microsoft

Forums: http://forums.microsoft.com MSSQLSERVER is the only one

I

carefully looked through the read me and got the installer to run successfully

with

setup /upgradesp sqlrun SECURITYMODE=SQL UPGRADEUSER=sa /L*v

C:\MSDELog.log

It showed the setup dialog and everything, but it STILL

has not upgraded, even though the setup ran, because when I do a



select @@version

I still get Service Pack

2

--

NEVER

MIND! It worked.

They really like to confuse you, don't they.

I see Microsoft SQL

Server 2000 - 8.00.2039 (Intel X86)


May 3 2005 23:18:38
Copyright (c) 1988-2003

Microsoft Corporation
Desktop Engine on Windows NT 5.1 (Build 2600:

Service Pack 2)

The 8.00.2039 is service pack 4, and the OPENXML now

works OK, so the rest of the version information (Build 2600: Service Pack 2)

seems to be a lie.

Thank you all for the

help.

MVPUser at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...

SQL Server

Site Classified