Showing posts with label differently. Show all posts
Showing posts with label differently. Show all posts

Monday, March 12, 2012

FOR XML works differently between Developer and Enterprise Edition in SQL 2005

If I run the same FOR XML query in a Development edition enviornment and a Enterprise Edition environment, the results are different. The query is exactly the same.

Here is the query:

DECLARE @.MessageBody XML
DECLARE @.AuditTable SYSNAME
DECLARE @.SendTrans BIT
DECLARE @.SendAudit BIT
DECLARE @.RecordCount INT
DECLARE @.OperationType CHAR(1)

SET @.RecordCount = @.@.ROWCOUNT
SET @.OperationType = 'U'
SET @.SendTrans = 1
SET @.SendAudit = 1
SET @.AuditTable = 'States'

SELECT @.MessageBody = (
SELECT * FROM
(
SELECT TOP 10
'INSERTED' AS ActionType, @.SendTrans AS SendTrans, @.SendAudit AS SendAudit,
COLUMNS_UPDATED() AS ColumnsUpdated, GETDATE() AS AuditDate,
@.AuditTable AS AuditTable, 'test' AS UserName, @.RecordCount AS RecordCount, *
FROM l_states
)AuditRecord
FOR XML AUTO, ROOT('AuditTable'), BINARY BASE64)

SELECT @.MessageBody

In my DEV env (Developer Edition), this result is produced:
<AuditTable>
<AuditRecord ActionType="INSERTED" SendTrans="1" SendAudit="1" AuditDate="2007-06-22T15:43:12.497" AuditTable="States" UserName="test" RecordCount="1" StateAbbreviation="AK" State="Alaska" />
<AuditRecord ActionType="INSERTED" SendTrans="1" SendAudit="1" AuditDate="2007-06-22T15:43:12.497" AuditTable="States" UserName="test" RecordCount="1" StateAbbreviation="AL" State="Alabama" />
</AuditTable>

In my Enterprise Edition evn, this is the result:
<AuditTable>
<AuditRecord ActionType="INSERTED" SendTrans="1" SendAudit="1" AuditDate="2007-06-22T15:44:48.230" AuditTable="States" UserName="test" RecordCount="1">
<l_states StateAbbreviation="AK" State="Alaska" />
<l_states StateAbbreviation="AL" State="Alabama" />
</AuditRecord>
</AuditTable>

Does anyone have any idea what might be wrong? Any help is greatly appreciated.
Tim

Tim,

What is the results of @.@.VERSION on both servers? (I suspect a difference in versions...)

Wednesday, March 7, 2012

FOR XML AUTO SQL 2K vs 2K5

The upgrade adviser for for 2k5 says something about derived tables being handled differently between 2k and 2K5 and it says to query the tables directly but this does not seem to make much sense because I thought FOR XML AUTO just created some generic XML for presentation purposes. These 2 stored procedures that it is complaining about do query the tables directly and they use the FOR XML AUTO to control the output.

Does anyone know if I have to worry about this? I am tempted to let this slide and check out this part of the application after the migration happens tomorrow for QA to start testing.

Yes I have been googling, checking my books and digging around in BOL. I am not seeing anything.

DISREGARD: I found my derived table. It appears to change the output of the XML. Perfect.I have never used FOR XML AUTO before. Looking over the descriptions of both the SQL 2K and 2K5 versions, the articles read almost identically. If the queries are relatively simple (not based on views, or subqueries), then I think you can just compare the 2K output to a similar 2K5 dataset, to make sure the XML is formed the same way.|||the difference is explained in the obvious location of sp_dbcmptlevel article in BOL 2k5. Off to the doctors office I go. Good thing I have a laptop so I can code in the waiting room.