Showing posts with label SQL Server 2008 R2. Show all posts
Showing posts with label SQL Server 2008 R2. Show all posts

20100129

Processing QBXML In SQL Server

I've been working with QuickBooks again, and this time I need to parse some QBXML in the database so I can do some data syncronization on a schedule.

SQL Server 2005+ has some nice XML tools that make things a lot easier.  I was having trouble getting things to show up, but eventually found some pretty basic examples.

I'm parsing an Invoice Query response.

Here is what I came up with:
-- variable to hold document reference
DECLARE @docHandle int

-- variable to hold actual XML
DECLARE @xmlDocument nvarchar(max) -- or xml type

-- Fill XML variable
SELECT TOP 1 @xmlDocument = QBXML FROM QBBridge ORDER BY QBBridgeID DESC

-- Use built in Procedure to process the XML into Data
EXEC sp_xml_preparedocument @docHandle OUTPUT, @xmlDocument;

    DECLARE @ParentID int
    DECLARE qbXMLCursor CURSOR FOR
        -- Get All InvoiceRet Objects.
        SELECT ID FROM OPENXML(@docHandle, N'/QBXML/QBXMLMsgsRs') WHERE NodeType = 1 AND LocalName = 'InvoiceRet'

    -- cycle through InvoiceRets and compile Sub Data.
    OPEN qbXMLCursor
    FETCH NEXT FROM qbXMLCursor INTO @ParentID

   
    WHILE @@FETCH_STATUS = 0
    BEGIN

        -- Use Common Table Expression to compile values to names of parent nodes
        -- I named my table columns <ParentName>.<ParentName>.<Name> so I'm sitting pretty for an insert from this.
        WITH InvoiceValues ([LocalName], [Value], [Level], [ID]) AS
        (
            SELECT    LocalName,
                    [text],
                    1 AS [Level],
                    [ID]
            FROM    OPENXML(@docHandle, N'/QBXML/QBXMLMsgsRs')
            WHERE ParentID = @ParentID
            UNION ALL
            SELECT    CASE WHEN SubValues.LocalName = '#text' THEN
                        InvoiceValues.LocalName
                    ELSE
                     InvoiceValues.LocalName + '.' + SubValues.LocalName
                     END As LocalName,
                    [text],
                    InvoiceValues.[Level] + 1 AS [Level],
                    SubValues.[ID]
            FROM    InvoiceValues
                    INNER JOIN OPENXML(@docHandle, N'/QBXML/QBXMLMsgsRs') As SubValues
                    ON InvoiceValues.ID = SubValues.ParentID
        )
        SELECT    [LocalName], [Value]
        FROM    InvoiceValues
        WHERE Value IS NOT NULL
           
        FETCH NEXT FROM qbXMLCursor INTO @ParentID
    END
    CLOSE qbXMLCursor
    DEALLOCATE qbXMLCursor

EXEC sp_xml_removedocument @docHandle


20091103

Windows 7 64 bit and SQL Server cliconfg

I recently did a wipe and Windows 7 install.  Installed all my dev tools, then tried connecting to some SQL Servers, local and remote, local worked fine.  I added some remote servers to my cliconfg by running (windows run dialog) 'cliconfg' it brought up the familiar server alias configuration tool, so I added my servers.  Then I tried logging into some of them, no luck.  Totally confused.

Turns out there are two cliconfg dialogs, a 32 bit and a 64 bit one, I had been getting to the 64 bit one, but my sql server management studio had been using the values from the 32 bit one.  Found the 32 bit one in "C:\Windows\SysWOW64\cliconfg.exe" started using it, and everything worked, still pretty annoying, I wish they would at least warn you, "oh hey, by the way, there are actually two cliconfgs"

Kind of silly.

*Edited, I had my cliconfg locations mixed up, I had assumed the one found in the folder referencing the number 64 would contain the 64 bit version.  This is wrong, though I remain confused because my brain refuses to believe the System32 folder on 64 bit windows would contain the x64 exe and the SysWOW64 directory would contain the x86 exe.  Thanks to Niels Grove-Rasmussen for the catch.

20091030

SQL 2005 FTS Thesaurus Doesn't Allow Duplicate Terms PROOF!

Was trying to find a way to use '&' and 'and' as expansions for my SQL 2005 FTS Thesaurus, and found this gem:
Because the thesaurus file already contains the term "Windows," the thesaurus file now contains duplicate terms. Therefore, the full-text thesaurus component does not load the thesaurus file.
From: http://support.microsoft.com/kb/923317

Again, would have been nice to know three Days ago.