Author: way0utwest

  • Inserting into an XML document

    I was reading through the latest XML Workshop article that I have from Jacob Sebastian. It’s a fantastic series for learning little bits of XML as you go and I’ve tried to read through most of them and learn something. I’m not a big XML guy, but I am trying to work on learning one thing each day.

    The article goes through this, but adding an element to an XML document is easy with the insert element syntax. I experimented a bit with Jacob’s syntax in a few ways. I decided I’d use the current list of books I’m reading as my data. Here’s my first thing:

    DECLARE @x xml          
    SET @x = ‘<Books></Books>’          

    DECLARE @name VARCHAR(50)
    SELECT @name = ‘The Federalist Papers’

    SET @x.modify(‘
        insert element Employee {sql:variable("@name")}
        into (Books)[1]
        ‘)

    SELECT @x

    That returned (spacing mine)

    <Books>

    <Employee>

      The Federalist Papers

    </Employee>

    </Books>

    As you can see, I cut and pasted Jacob’s code before playing with it, so I have the inner element name wrong. I fixed that, and then added a second insert.

    DECLARE @x xml          
    SET @x = ‘
    <Books>
    </Books>’          

    DECLARE @name VARCHAR(50)
    SELECT @name = ‘The Federalist Papers’

    SET @x.modify(‘
        insert element Book {sql:variable("@name")}
        into (Books)[1]
        ‘)

    SELECT @name = ‘Treasure Hunt’

    SET @x.modify(‘
        insert element Book {sql:variable("@name")}
        into (Books)[1]
        ‘)

    SELECT @x

    Which returned this (my spacing):

    <Books>

      <Book>The Federalist Papers</Book>

      <Book>Treasure Hunt</Book>

    </Books>

    I left out the first keyword, but I’ll add it in here.

    DECLARE @x xml          
    SET @x = ‘
    <Books>
    </Books>’          

    DECLARE @name VARCHAR(50)
    SELECT @name = ‘The Federalist Papers’

    SET @x.modify(‘
        insert element Book {sql:variable("@name")}
        into (Books)[1]
        ‘)

    SELECT @name = ‘Treasure Hunt’
    SET @x.modify(‘
        insert element Book {sql:variable("@name")}
        into (Books)[1]
        ‘)

    SELECT @name = ‘Total Recall’
    SET @x.modify(‘
        insert element Book {sql:variable("@name")}
        as first
        into (Books)[1]
        ‘)

    SELECT @x

    That gives me the first book as Total Recall, which is a great book.

    <Books>

      <Book>Total Recall</Book>

      <Book>The Federalist Papers</Book>

      <Book>Treasure Hunt</Book>

    </Books>

    I checked books inline for the insert command and found that there are first and last keywords you can use for elements, but not attributes.

    I decided to get fancy with an attribute then. I wanted to add the author attribute for the book Total Recall. So I tried a little hard coding. I knew this was the first element in my document (below the root), so checking the example in Books Online, I tried this:

    SELECT @name = ‘Jim Gemmell’
    SET @x.modify(‘
        insert attribute author {sql:variable("@name")}
         into (/Books/Book[1])[1]
        ‘)

    It worked! I got this result.

    <Books>

      <Book author="Jim Gemmell">

        Total Recall

      </Book>

      <Book>The Federalist Papers</Book>

      <Book>Treasure Hunt</Book>

    </Books>

    Nothing amazing here, but since I don’t work with XML data much at this level, it was kind of cool to use Jacob’s article and actually accomplish something.

  • Plagiarism Again

    Update: The problem posts have been removed from the SQLTechConsulting site.

    I ran across a note from Brent Ozar (blog | Twitter) on Plagiarism, Inspiration, and John Dunleavy yesterday, having missed what looks like an interesting Twitter discussion since I’m halfway around the world from where I usually am. However in reading this post, and the Twitter notes, I am actually shocked at someone defending an undefendable position.
    It’s like having a child put their fingers in their ears, while closing their eyes and singing “la-la-la-la” in response to a parent.
    John, dude, you’re wrong. You’re not syndicating, you’re not “helping others to learn”, you’re plagiarizing content from other sites. From other writers, and passing it along as your own content. Providing a link is not enough to give credit to someone else.
    You can read Brent’s post to get some of the story, and I have had emails in the past with John, requesting that my content be removed from his site. Just so that it’s clear how I feel, a few examplse below of what I think is wrong.
    Here’s a post from SQL Tech Consulting:
    sqltech1
    This post is “by John” (emphasis mine) and links to a note at MSSQLTips. That’s fine, and that’s a good example of writing your own  content and linking to others, though I think there ought to be some mention here of MSSQLTips.
    Here’s another one:
    sqltech2
    This is also “by John”, but the content isn’t by John. This is actually content taken directly from the MS link for the download page. This is re-publication and reproduction of content, implying that it’s by John at SQL Tech Consulting.
    It’s not.
    This by someone at Microsoft, and this is a copyright violation. All the text of this post is not John’s work.
    I link to articles from SQLServerCentral on other sites. I credit those sites, as shown below, only reproducing a small abstract with credit.
    ssc_copy_1
    SQL-Server-Performance links to my content in their newsletter, and next to every title it clearly says “SQLServerCentral”, so you are aware of who the publisher is. There is no mistake. What’s more, sql-server-performance doesn’t co-mingle my content with theirs, as shown below. Unlike SSWUG, who some people believe is mis-leading readers, they only show their published articles.
    ssp-1
    SQL Tech Consulting is violating copyright in re-producing content, and the lack of a citation is  plagiarism. It’s ethically wrong, and there is no defense. Not giving credit to the authors, or the publishers, is in-defensible. There’s no excuse. It’s not syndication, and as noted by many people, it’s not with permission. Even if it is, you must give credit, and note, “reprinted with permission.”
    I’m not sure if SQL Tech Consulting doesn’t understand these concepts and wants to imply to current and potential customers that they have more knowledge than they have or if they just want to attract more business and think this will raise their search engine rating.
    In either case, this type of behavior means it isn’t a company I’d hire.

  • Be Responsible in your blogging and posting

    I have been awarded the MVP award from Microsoft a few years in a row and it’s an honor, but it’s also a responsibility. One of the benefits from the award is that I get information about what is coming up in products, often under an NDA (non-disclosure agreement). That means that I can’t release this information publically, and every quarter it seems that one or more MVPs lose their award for disclosing information they shouldn’t.

    The same thing ought to apply to the posts you make, blogs you write, etc., when it might apply to your company. I wrote an editorial at SQLServerCentral on this recently, and it is something that you ought to keep in mind for not only posts, but also discussions you have with friends.

    Be responsible in your career, and don’t disclose information that you shouldn’t.

    (cross posted to The Modern Resume)

  • Losing Two Days

    I’m off tomorrow to the UK for a week of work at the Red Gate offices, and then a couple days of vacation. My oldest is graduating from high school this year, and as a present, we’re taking him and the rest of the family to the UK for a week. My family actually leaves Mon and will arrive Tues, and they are there for a week, coming back the following Tuesday.

    It’s not a trip I’m looking forward to. Going to Red Gate is fine, but the 10+ hour flights and being out of my routine for a week bugs me. I don’t like traveling this much. I prefer the short, two day SQL Saturday trips.

    With cutbacks on all airlines, it becomes harder to travel these days. Even going to the East Coast from Denver requires 2-3 days for work. I used to be able to catch an early flight from Denver to somewhere like NY in time for a lunch meeting on the East Coast, working half a day, and coming home late at night. These days it seems like you always have to leave the night before, and possibly stay another night if you want to work until 5pm.

    The UK is worse. I leave Sat morning, arriving early Sun morning. I would leave Sunday, but I have had issues with delays, and I have work to do Monday. Plus I hate being exhausted that first day at work more than I hate traveling. That’s a day of travel plus a slightly lost day of my weekend on Sun. I’ll probably work on Sun to get things done and get a little ahead.

    Coming back we leave on Tuesday morning, arriving late afternoon in Denver that day. However another day lost to travel, and even though it isn’t a vacation day, it’s a lost day of work. In the world I live in, which is a grinding daily list of things to keep the site running, it puts me behind. Even with someone helping out, I usually take a few days to get caught back up.

    I’m dreading this next long week, and will likely be a little out of touch on the site. Hopefully everything still runs smoothly.