Tag: syndicated

  • T-SQL – Finding Changes

    Someone posted a note recently asking about how to detect the changes in a sequence. Say you have a table like this:

    DECLARE @t_temp table (ID INT IDENTITY(1,1), Value VARCHAR(20))
    insert into @t_temp
    select 'Win32' UNION ALL
    select 'Win32' union ALL
    select 'Win32' union ALL
    select 'Win32' union ALL
    select 'Win32' union ALL
    select 'Win32' union ALL
    select 'Win64' union ALL
    select 'Win64' union ALL
    select 'Win32' union ALL
    select 'Win32' union ALL
    select 'Win64' UNION ALL
    select 'Win64'
    SELECT * FROM @t_temp

    .csharpcode, .csharpcode pre
    {
    font-size: small;
    color: black;
    font-family: consolas, “Courier New”, courier, monospace;
    background-color: #ffffff;
    /*white-space: pre;*/
    }
    .csharpcode pre { margin: 0em; }
    .csharpcode .rem { color: #008000; }
    .csharpcode .kwrd { color: #0000ff; }
    .csharpcode .str { color: #006080; }
    .csharpcode .op { color: #0000c0; }
    .csharpcode .preproc { color: #cc6633; }
    .csharpcode .asp { background-color: #ffff00; }
    .csharpcode .html { color: #800000; }
    .csharpcode .attr { color: #ff0000; }
    .csharpcode .alt
    {
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
    }
    .csharpcode .lnum { color: #606060; }

    This gives you a simple table and it has these values. Note the first column is just a row counter from the client, the ID and Value columns contain the data.

    table_sequence

    If you wanted to detect when the Value changes, you’d be looking for the rows with IDs 7, 9, and 11. A simple query gets you that.

    select t1.ID, t1.Value
    from @t_temp t1
    join @t_temp t2
    on t2.ID = t1.ID - 1
    where t1.Value <> t2.Value

    This easily gets those values. However identities aren’t guaranteed to be sequences. What if I deleted row 11 and added another row.

    If I add in this code:

    INSERT @t_temp SELECT 'Win64'
    DELETE FROM @t_temp WHERE ID = 11

    And I run the query, I get 7, 9 on my system. A better way to do this is to actually use a subquery to find the previous value in the sequence, not assume it’s one less. Here’s an easy way to do this

    select t1.ID, t1.VALUE
    from @t_temp t1, @t_temp t2
    where t1.id > t2.id
    and t1.Value <> t2.VALUE
    AND t2.id = (SELECT MAX( id)
    FROM @t_temp t3
    WHERE t3.id < t1.ID
    )

    In that subquery, I add a third instance of the table, and I look for the largest ID value that is less than what I’m using as my “current” row in t1. This allows me to find a 10 in t3, and match that to t2 when t1 has the value 12, the next value above 10.

  • Speaking and Presenting Tips – Handouts

    I’ve given quite a few presentations, one keynote with another to come, and attended many more. I’ve read a few books on how to get better, and then in an Edward Tufte seminar recently, I got another one.

    Dr. Tufte mentioned the idea of a supergraphic, an image with a ton of information in it. I think that some BI systems are starting to think of this as something to display to users. Dr. Tufte said that most screens, especially with projectors, can’t really put up the resolution, and I’d agree. Here’s an image I found online:

    supergraphic

    This is the idea. A ton of information on one piece of paper that you can give out to people. He said that as a presenter if you find one of these, you can likely “dine on it” for years. Here’s another example he showed from the course.

    minard

    It’s actually about Napoleon’s march into Russia in the early 1800s. There were other examples, but I didn’t see any online and didn’t want to play with a scanner.

    The idea here is that you give people a bunch of information. Most of it might not matter to each person, but each person will look at something. They’ll also begin to process the data themselves, and let you highlight, talk about, or even encourage debate on the material.

    I’m not sure how I’d do this in a tech presentation, but I definitely can see that if you are presenting a lot of information, especially some type of report to others, this would make sense. I’m going to keep this in mind for future presentations I do, and perhaps even build a Modern Resume supergraphic.

  • Finding SQL Server Client Ports

    I saw a post recently asking if there was an easy way to find the port a client was using on a SQL Server since someone had multiple instances. I asked for some information since there are actually multiple ports in use.

    The port the SQL Server listens on

    The port the client server opens a connection on their side

    The first one comes from a few places. It’s easily found in the Configuration Manager GUI as shown below:

    SQLServerPort

    These are the TCPIP properties for my service.

    Finding the client port, which is probably needed for tracing/troubleshooting, is easy to do as well. You can query sys.dm_exec_connections, and see how clients are connected. I don’t have any TCP connections on my instances, since I am local it’s through shared memory, but here’s where you’d find it in the result set:

    SQLServerPort2 

    I’ve typically not worried about port, but the client_net_address has been valuable to me in the past.

  • I’d buy an iPhone4, but ….

    I don’t trust ATT.

    That’s saying something. AT&T, the company that built US telco, that gave us innovations from Bell Labs, including Unix. They got an exclusive deal for the coolest phone I have ever used, and I don’t trust them.

    Their network, despite upgrades, still has me worried. There are so many people I know with iPhones that hate the company. They have constant issues with both voice calls and data access. If I had even 50% of my ATT friends happy with the service I’d order an iPhone 4, switch to ATT and be happy.

    Instead I’m at a bit of a crossroads.

    Not that T-Mobile is that great. Last night I had to turn airplane mode on/off to get a data connection to sync up. There have been issues with T-Mo in my area at times, and I don’t get data access most of the time I’m near the house. Not a huge big deal as I have wifi at home, but annoying at times.

    I have an iPhone 2G, jailbroken and running on T-Mobile. I’ve had it over a year, after having a Google G1 (Android 1.5, 1.6) and a T-Mobile Dash (WinMo 6.0) and the iPhone blows them away. In terms of what I use it for, I have email (so-so), calendaring (crappy), music (excellent), reading (excellent), camera (excellent), lots of special purpose apps for things like banking, travel, etc. that I use. Trying to do things in a browser, even a mobile site on a cell phone sucks. Many times it’s not even usable. However many things that I do need, and use often, have fantastic apps on the iPhone.

    It’s not the best business phone, but it’s a great one.

    The iPhone wins for me, mostly because of the platform. Music/reading/apps that work for me. Android is getting close, with the Kindle app coming, and (hopefully) Google Music with a desktop sync that works. Android 2.2 looks interesting, but until the platform gets more mature, with more useful apps and capabilities that I need, I won’t move.

    So the rest of you, please, please, please, order your iPhone 4s now so that I can pick up a used 3GS, crack it, and upgrade to iOS4 🙂