Category: Blog

  • Getting a Page of Results

    The other day I was looking over a couple of articles on paging, looking to see if I could learn something new in T-SQL. I’ve implemented some SQL2000 era paging systems, none of which performed wonderfully, so I checked out Jacob Sebastian’s basic Server Side Paging and Paul White’s Optimizing Paging Part 1.

    I’ve done systems similar to Jacob’s, but he had an interesting use of the OVER clause in his code. He had this code:

    ;WITH emp AS (
      SELECT 
        CASE 
          WHEN @SortOrder = 'Title' THEN ROW_NUMBER()OVER (ORDER BY Title) 
          WHEN @SortOrder = 'HireDate' THEN ROW_NUMBER()OVER (ORDER BY HireDate) 
          WHEN @SortOrder = 'City' THEN ROW_NUMBER()OVER (ORDER BY City) 
              -- In all other cases, assume that @SortOrder = 'LastName' 
          ELSE ROW_NUMBER()OVER (ORDER BY LastName) 
         END AS RecID,   , LastName
       , FirstName
       , Title
       , HireDate
       , City
       , Country
       , PostalCode
     FROM employees

    This is a great solution in SQL Server 2005. It’s much different than what I had done in SQL 2000, where I’d typically approach the problem by using the sort key to get the next page.

    So say I had this data in a table (Customers):

    CustomerID    Customer

    ———–   ————

    1             Jones

    2             Smith

    3             Johnson

    4             Allen

    5             Gates     

    Then suppose I wanted page 1, 2 results per page, ordered by Customer. I would want to see “Allen, Gates” on page 1. I’d use this code.

    select top 2 Customer

    from Customers

    Order By Customer

    If I wanted page 2, I’d go here:

    select top 2 Customer

    from Customers

    where Customer > ‘Gates’

    Order By Customer

    And this would get me “Johnson” and “Jones” since the WHERE clause would reset results. If you have control of the application code, and you can pass in the previous values, you can easily build pages like this.

    If you switch orders, say to the CustomerID, then you can easily pass that in as well, and use that for ordering.

    There is a downside, however. Any ideas? I’ll post that in my next look at paging.

  • Syndication Schedule Changes

    We have a process that reads syndicated blogs from people and then publishes them here. It’s worked well, and allows people to have their own site, but get more exposure here. I actually use it, publishing a copy of my blog at Blogger and then having it read here. Gives me peace of mind to have a backup copy.

    However this week I noticed an issue. A few times people have pinged me saying that they posted something and it didn’t appear that day. I hadn’t worried about it until the T-SQL Tuesday blog party. The rules for that party require that you get a post in on Tuesday, which for many people involves scheduling a post earlier.

    So our process doesn’t pick it up on Monday (it’s scheduled) and while it probably comes in late Tuesday, it misses out on the blog party.

    I submitted a ticket and asked for the way to run the process ad hoc. That way I could get my posts in and when people pinged me, I could just run it. However the Ops guys didn’t like that, so I got a response that they’d schedule it every 8 hours instead.

    That works, and this post is a test to see if it actually works.

  • eReading – Lending Books

    I sent this to Barnes and Noble, as well as Random House recently after the much vaunted “lending” technology in the Barnes and Noble e-readers didn’t work as expected for me.

    My wife pinged me this morning, asking about the “lending” technology on Barnes and Noble.

    I just went to try and lend an e-book to my wife on Barnes and Noble. We typically do a lot of e-reading as it’s more convenient for us. I wanted her to try a new author, but don’t want to give up my device. However, the novel, in this case Grift Sense from James Swain, wasn’t lend-able.

    I understand this is a publisher limitation. Please remove this. It’s asinine to expect that the capabilities of physical books, i.e. lending, should not be allowed. It’s not a copy, I lose the book while it’s lent, which is perfectly acceptable. The sharing of books is a great way that I’ve gotten other people interested in authors, and I’ve gotten interested as well. Letting me share a book I like with a friend, for some reasonable time, is a way to promote reading, not kill your sales. I would also like to be able to "sell" my ebooks, though I think we are a little ways away from that technology.

    E-reading for me over the last couple years has had me moving from reading about 50 books a year to more than 70. I now buy my books instead of going to the library as much and that’s fine. I’m happy to pay for good content. But stop trying to restrict things. Please make all your titles available as e-books, and make them lend-able.

    I like the idea of sharing books, especially when we don’t share accounts. My wife and I had separate accounts on B&N, though we’ve been looking to go to a merged account so that we each can see books the other has read. It’s silly for us to have to re-buy a book within the family.

    I think this is one place the the publishers are going to have to let go a little and trust people to do some sharing. Most people I know are comfortable buying books, and they make the investments. Don’t penalize them to prevent e-reading.

    I also think that B&N or Amazon could get ahead of the curve here and allow us to “re-sell” our used e-books to others. By putting up a market for people that want to sell their e-books, they could allow us to even buy more books with the money we make.

  • Negotiating Salary for a New Job

    Slightly off topic, but I’m adding this one to the Modern Resume blog since I think it’s something to be aware of in managing your career, and to some extent, your brand. How you handle this reflects on you, and I wanted to note a little advice.
    I ran across this post from Brent Ozar on salary negotiations that gives some advice. It was in response to a Twitter post, which proves one great thing about where you can get inspiration: Twitter! For the most part I agree with Brent’s advice, but I have a slightly different take on how to handle it.

    Ask, Don’t Answer

    My basic advice is that you ought to get an idea of what the job is paying first, and as soon as possible. Money does matter, and it can break negotiations down if the number of too low.
    There is no good average salary for some jobs. I know that HR people like to think there is, but I have seen it quite often that the ranges for a particular job, and skillset, can vary widely in companies. I think that it’s it’s in part because the value placed on a particular job can vary widely from company to company. However, I would say that the majority of the issue is that most people are poor negotiators.
    I’m getting slightly off track here, but my first advice is that early on in the initial interview, probably over the phone, you get an idea of the salary range the company is looking to pay. If they ask you what you are making, tactfully ask them what the job pays. If they press let them know that you do not necessarily want to disclose your salary right now until you find out more about the job. Defer the discussion.
    Why?
    If you are expecting, or need, to make $75,000/yr and the job is for $55,000/yr, there might not be a point in continuing.  I’ve had that happen to me (not those numbers, but a similar experience) and it spurred me to ask them if that was a hard range or could anything be done to raise it. I have let them know that I can’t work for that number and in some cases they considered raising it, some they didn’t. However if it’s a make or break number, then it’s good to get that out of the way up front and stop wasting each other’s time.
    After that, I think I’d follow Brent’s advice and give you current salary as a multiple of 10. You make in the “60s” or the “80s”, but there’s no need to give an exact figure. Information is power, and a sharp negotiator, like an experienced HR person or manager, will use an exact number to beat you down on your salary.

    Have Reasons

    Whether you hoping to make more money, or take a pay cut, have reasons for your move. Keep in mind that anything you say as a slight against your current situation could be seen as a potential negative to a new employer. Tread carefully, but honestly in your reasons for your new salary (up or down).
    Above all, be honest. There’s no reason for you to lie about your salary, and it can only hurt later on down  the road if someone finds out. Give an honest range in which you currently fall.
    Lastly, the best argument is that they are paying you to do a job, and even if that job is paying 20% more than you currently make, if they think you can do the job, they should pay you.