Re: Incorrect XML returned
From: Graeme Malcolm (graemem_cm_at_hotmail.com)
Date: 08/27/04
- Next message: Buddy Ackerman: "Re: Incorrect XML returned"
- Previous message: Buddy Ackerman: "Re: Incorrect XML returned"
- In reply to: Graeme Malcolm: "Re: Incorrect XML returned"
- Next in thread: Buddy Ackerman: "Re: Incorrect XML returned"
- Reply: Buddy Ackerman: "Re: Incorrect XML returned"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 27 Aug 2004 18:25:24 +0100
Also, the JOIN clause looks a little odd to me. I'd have thought it should
be:
SELECT *
FROM dbo.vUsers u
JOIN dbo.vUserGroupApps app ON u.UserGroupID = app.groupid
JOIN dbo.vAppPermissions permission ON app.appid = permission.appid
WHERE u.sid = 1
FOR XML AUTO
It seems to work with the AND clause embedded in the JOIN, but it makes the
code a little confusing.
The final thought is that FOR XML formatting relies heavily on the data
being returned in the correct order, so it's probably a good idea to add an
ORDER BY clause to the query (and maybe specify the actual columns you want
returned rather than using SELECT *)
Hope that helps,
Graeme
--
----
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"Graeme Malcolm" <graemem_cm@hotmail.com> wrote in message
news:uUvg7hFjEHA.2580@TK2MSFTNGP10.phx.gbl...
Can you post your DDL. I tried the following, and I got results similar to
what you expect:
-- My DDL:
CREATE TABLE vUsers
(sid int,
uid nvarchar(20),
[password] nvarchar(20),
UserGroupID int)
CREATE TABLE vUserGroupApps
(groupID int,
appId int,
[appName] nvarchar(20))
CREATE TABLE vAppPermissions
(
appid int,
permissionid int,
descr nvarchar(20)
)
GO
INSERT vUsers
VALUES
(1, 'JDoe', 'test', 1)
INSERT vUserGroupApps
VALUES
(1, 1, 'TestApp2')
INSERT vAppPermissions
VALUES
(1, 1, 'Test Permission')
INSERT vAppPermissions
VALUES
(1, 2, 'Test Permission2')
GO
select *
from dbo.vUsers u
join dbo.vUserGroupApps app on u.UserGroupID = app.groupid and
u.sid = 1
join dbo.vAppPermissions permission on app.appid = permission.appid
for xml auto
--My results:
<u sid="1" uid="JDoe" password="test" UserGroupID="1">
<app groupID="1" appId="1" appName="TestApp2">
<permission appid="1" permissionid="1" descr="Test Permission"/>
<permission appid="1" permissionid="2" descr="Test Permission2"/>
</app>
</u>
--
----
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"Buddy Ackerman" <buddy_nospam@buddyackerman.com> wrote in message
news:%23BVkG2EjEHA.2412@TK2MSFTNGP15.phx.gbl...
I have the following query:
select *
from dbo.vUsers u
join dbo.vUserGroupApps app on u.UserGroupID = app.groupid and
u.sid = 1
join dbo.vAppPermissions permission on app.appid = permission.appid
for xml auto
There is one vUsers record meating the criteria and one vUserGroupApps
for that user and two vAppPermissions records relating to the one
vUserGroupApps record. I expected to get the following returned XML:
<u sid="1" uid="jdoe" password="test">
<app groupid="1" appid="1" appName="Test App2">
<permission appid="1" permissionid="1" descr="Test Permission"/>
<permission appid="1" permissionid="2" descr="Test Permission 2"/>
</app>
</u>
What I actually got was this :
<u sid="1" uid="jdoe" password="test">
<app groupid="1" appid="1" appName="Test App2">
<permission appid="1" permissionid="1" descr="Test Permission"/>
</app>
</u>
<u sid="1" uid="jdoe" password="test">
<app groupid="1" appid="1" appName="Test App2">
<permission appid="1" permissionid="2" descr="Test Permission 2"/>
</app>
</u>
Why did it return the second format and not the first.
--Buddy
- Next message: Buddy Ackerman: "Re: Incorrect XML returned"
- Previous message: Buddy Ackerman: "Re: Incorrect XML returned"
- In reply to: Graeme Malcolm: "Re: Incorrect XML returned"
- Next in thread: Buddy Ackerman: "Re: Incorrect XML returned"
- Reply: Buddy Ackerman: "Re: Incorrect XML returned"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|