Jul 29

Fun with SQL and in line queries

So I’ve grown to not like the coding style of the guy before me at all. Some of his methods are quite, recursive and hellish when it comes to SQL. Several times, the easy way was taken rather than the correct way. To give you a bit of background, the main application I support controls at outbound call center. Agents log into the system and dial out with it. In order to track what a current agent is doing there is a table called actions. Everything from logging in, logging out, and more is logged here. Over the past 2 years, this has led to over 7 million records in the table. If you’re not a tech person, it’s about to get deep.

In order to determine if a user is logged in, the previous programmer would do the following. Query the database for all users with a type of 2 (call center agent). After that for each user in the database of type 2 (call center agents, currently ~120 agents exist), he would query the actions table for the users last action, whether it’s action type 1 (login) or 2 (logout). If the first returned row is of action type 1, the user is logged in. Lastly, the code queries the actions table to see what the last campaign a user logged into. (action type 20). After throwing in some basic code to track the queries and time of this (and thanking John Davis along the way for teaching the importance of big O notation) I learned that an average check of who’s logged in totaled around 150-200 queries along with taking 45 seconds to a minute. So this was one of my goals in Nashville last week, to write one massive query I could use to get the results I’m looking for. To assist me in the insanity, I called master of all that is shoes, Brian Schumacher. We worked together back at Irresistible Ink as data developers and since he’s gone on to be a DBA in Klamath Falls, Oregon. Well he quit last week but that’s his story not mine.

So after about 45 minutes of being on the phone and utilizing the greatness that is pastebin, we worked out a viable solution. I present to you, possibly the most complicated query I’ve written to date.

SELECT
loggedIn.lastname, loggedIn.firstname, campaigns.cpnname, DATEDIFF(ss,[actions_4].[actionwhen],getdate()) AS LoggedIn, DATEDIFF(ss,[actions_3].[actionwhen],getdate()) AS CampaignLogin
FROM
(
SELECT
employees.unqempid, employees.lastname, employees.firstname, ActionIDLoggedIn.actionID
FROM
(
SELECT
unqempid, MAX(actionid) AS actionID
FROM
actions
WHERE
(actiontypeid = '1')
GROUP BY unqempid
) AS ActionIDLoggedIn
INNER JOIN
(
SELECT
unqempid, MAX(actionid) AS actionID
FROM
actions AS actions_2
WHERE
(actiontypeid = '2')
GROUP BY
unqempid
) AS ActionIDLoggedOut
ON
ActionIDLoggedIn.unqempid = ActionIDLoggedOut.unqempid AND
ActionIDLoggedIn.actionID > ActionIDLoggedOut.actionID
INNER JOIN
employees ON employees.unqempid = ActionIDLoggedIn.unqempid
WHERE (employees.type = 2)
) AS loggedIn
INNER JOIN
(
SELECT
unqempid, MAX(actionid) AS actionID
FROM
actions AS actions_1
WHERE
(actiontypeid = '20')
GROUP BY
unqempid
) AS maxCampaign
ON maxCampaign.unqempid = loggedIn.unqempid
INNER JOIN
actions AS actions_3 ON maxCampaign.actionID = actions_3.actionid
INNER JOIN
campaigns ON actions_3.actioninfo = campaigns.cpnid
INNER JOIN
actions AS actions_4 ON loggedIn.actionID = actions_4.actionid
ORDER BY
loggedIn.lastname, loggedIn.firstname

The end result, we’ve shortened this down to 1 query that takes 2-3 seconds. Hopefully this post can only serve as help to some programmer stumbling along a similar problem as mine.


Jul 25

Hell, turn right

Posted in:Personal | 1 Comment »

DSC00332

So I’ve now spent 2 days in Nashville and I’ve learned quite a few things. The first of which is if you’re ever IT and going to an area to be told their problems, you’re fresh meat. I’ve spent alot of time being told the seventeen thousand things the previous programmer of the application I now manage screwed up. I still like the job, in fact since I know how much of a difference it will make I’m pretty pumped to get started. However I have decided to re-write the application the way it should have been written so it doesn’t resemble a plate of spaghetti. I actually just got home from a joyous 10 hour day. I made a few tweaks to the system to improve it overall.

I did take an hour long break however to run to the bookstore. I ended up leaving with 3 things I think will help my career. The first being the heavily work related book, MS SQL Server 2005 Unleashed. One of the things I wasn’t told is that I’ll be fulfilling the role of database administrator, and my MS SQL is a bit weak compared to MySQL. Thus I picked up the book so I can brush up where need be. Secondly, an issue of HOW magazine, which is much like Cre@te magazine, a designer magazine I used to read. Lastly, and my favorite purchase in iWoz, the autobiography of Steve Wozniak. For those of you that aren’t familiar with Woz, he’s solely credited for the creation of the personal computer, and co-founder of Apple. Hopefully by reading this, somehow I can watch my desire for the iPhone subside.


Jul 23

Nashville?

Posted in:Personal | 1 Comment »

DSC00197

Well I’ve had an excellent few days off. Played a few great dj gigs. I also splurged a little and picked up a digital camera. After doing a bit of research (i.e. calling my Uncle Mike) I decided it was time for me to own a digital camera finally. For a point and shoot, it seems to do fairly well with a bit of tweaking. Because of this, I also setup a Flickr account to host my pictures. They make it so easy, it seems to make more sense than setting up Coppermine or Gallery. Sometime this week I’ll probably setup a Flickr plugin with WordPress to share my pictures with everyone.

I’m flying out to Nashville tonight for work. It’s my first time actually being sent anywhere for work so I’m excited, and of course I’m going to take lots of pictures. Work has been going great although I feel a bit overwhelmed with everything they want to do. Everything has to be done yesterday it seems. The past 5 day weekend has been the recharge I’ve needed.


Jul 16

Hacking at work for fun and a paycheck

Posted in:Tech | 1 Comment »

So at the new job we have a few offices in different locations of country.  For example, next week I’m heading to Tennessee to experience the call center application I’m working on first hand.   I had just relocated one of our databases from the Michigan office to our sql server here in Minnesota and a report that a user from Michigan runs broke in the process.  The user called in to report the report had to be run but she wasn’t at her system.  I was told that remote desktop was disabled on these systems but the passwords I was given weren’t working properly.

After some failed attempts at remotely starting remote desktop, I started looking into ways to get into VNC.  They weren’t running the older vulnerable version of so that was out of the question.  After doing a bit of google searching I came across a utility called vncpwdump which allows you to dump the existing password from the registry.  Unfortunately the program was only giving me a portion of the password.  Instead I decided I was approaching this the wrong way.   I went ahead and changed my VNC password to a temporary password and then exported the registry key.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\RealVNC\WinVNC4]
“Password”=hex:aa,aa,aa,aa,aa,aa,aa,aa
“SecurityTypes”=”VncAuth”
“ReverseSecurityTypes”=”None”
“QueryConnect”=dword:00000000
“dummy”=”"

Then using Connect Network Registry option in the registry editor, I imported my registry file to the remote system.  Voila!  


Jul 16

The downfall of the United States

Posted in:Rants | No Comments »

First off, I’m going to admit up front, I’m not against rap music. I used to only listen to rap music just a few years ago. I like to think that I’ve expanded my music horizons enough to not be biased towards one type of music. That being said, rap has turned to shit. Even tracks like Usher’s Yeah didn’t bother me. This new crunk hop phrase of music that’s slower than 85 beats per minute drives me nuts. When I’m djing someone comes up to me and asks “can you play something I can dance to?” This happened last Friday and the girl in question wanted to hear the new track by Hurricane Chris entitled, A Bay Bay. At this point, I’d like to introduce exhibit A.

When I Holla Ay Bay Bay
I Finna Get My Groove On
Its So Hot Up In Da Club
Dat I Ain’t Got No Shoes On
Im Holdin’ Up A Big Stack And Dem
Hundreds In A Rubba Band
Girl Don’t Ask Me For No Cash
Cause Im Not Dat Other Man
Everybody Trippin’ Cause Im Limpin’
When Im Walkin’ And Im Pimpin’ When Im Talkin’
I Don’t Trick On Chick Dats Talkin’
Dem Boyz In Da Back Dey Be Rollin’up Dey Doughdy
Then Dey Blow It Till Dey Chokin’
Dats Wat Godly Came Out

Over the weekend I heard this song playing in approximately 75 cars. I severely wish that people in general would be more open to music that is actually able to be danced to. Yes, now I sound like a hypocrite but stick with me. The only way people dance to the new wave of rap / hip hop is follow the last word, hop. You put your hand up in the air and hop singing the words. Please, kill me now. The thing that gets me is people want to hear this style of crunk hop song after song. I gladly rip through the 10 big crunk hop balls of poo in 5 minutes so I can tell the people asking for them “I’m sorry, I already played that song”. So in conclusion, I can’t wait for someone to come up with a new style of rap / hip hop. Please at least be club friendly and use words in the english language.

To finish up, I’ll leave you with Chris’ interpretation of T-Pains, Buy You a Drank.


Jul 12

The urge to want

I don’t understand it.  I get these urges to have something every now and then.  Usually its some bit of techno wizardy.  Be it a cell phone, or the XBox 360 on my shelf, of my tv.  Money vexes me. If I have have it, it screams at me, get me out of your bank account, NOW.  Sure I’m usually happy with whatever it is I just have to have but it makes saving money particularly hard.  That being said, I’m going to start actually saving money.  Someday I need to buy a house and I’m making too much money to not be saving.  Someday I’ll have all of these debts paid off.  Then I’ll buy a house.. or a Sky Redline.. or.. okay I’ll stop.


Jul 12

Pownce

So my long time e-friend ht recently sent me an invite to Pownce. Pownce is alot like Twitter but from one of the guys over at Digg. The basis of the site is a social network that appears to be taking a minimal approach. Where Myspace and Facebook bombard you with bulletins, event invites, friend requests, and individual pages, Pownce takes a more minimal approach, giving you the data you need and that’s it. At present I don’t see any ads however the mention of going pro offers sending files up to 100MB and no ads for a reasonable $20 / year. Whether I’ll hold on to this or watch it fade away as another page I’ve made an account for I’m not sure yet. If I keep using it I’ll write up a list of pros and cons. Until then, if you’d like an invite to the invite-beta, let me know and I’ll send one over.


Jul 11

Windows Vista and terminal service

Posted in:Tech | 2 Comments »

I actually stumbled across this a few days ago at work.  While trying to remote desktop into our terminal server,  I kept experiencing some odd slowdowns as if the connection was intermittently working.  The odd thing, is I had no issues while typing in my password or typing in a window when I turned up the command prompt.  After doing a bit of searching I came across some sites that explained what was going on.

With Windows Vista a new technology referred to as autotuning was introduced.  This feature enables the system to adjust the size of tcp packets beyond 64kb.  To do this, a SYN packet to negotiate a larger packet size is sent to the client.  This is all fine and dandy except that some routers think this is something else and strip the acknowledgment packet so the server starts running with the new packet size, and the client sits dumbfounded.

To make a long story short, I disabled autotuning with the following command:

netsh interface tcp set global autotuning=disabled

After which, I was able to remote desktop to my hearts content.  The reason this only occured with our 2003 server was that our 2000 servers don’t support autotuning.  Go figure.


Jul 10

MSSQL to MySQL migration

Posted in:Tech | 2 Comments »

Well today I start the initial steps of migrating our MSSQL databases to MySQL.  One of the first tasks here at the new job was to determine where our MSSQL licensing was at.  We’re currently running a version of MSSQL 2000 Personal edition so we either need to migrate or get our servers legal.  <rant> Our existing setup is 2 servers, 1 IIS server, and another dual processor system running MSSQL.  Due to Microsoft’s awesome licensing setup, in order to be legal we need to purchase 2 MS  Windows Server Unlimited Connector licenses.  The part that makes no sense, is one is for the IIS server, the other is for the SQL server.  I can understand one, but the second is ridiculous.</rant> So in the end, it’s pay $17,000+ to be legal, or move MySQL, which in the benchmarks I can find, smokes MSSQL.

After this, I went ahead and installed the MySQL migration tools on the MSSQL due to the application crashing on the CentOS box.  I had to modify the grant tables to allow root to remotely connect to the system.  After this, I ran into a small pitfall of the Migration tool.  The default value of some of the fields in my table refer to MSSQL functions, which aren’t compatible with MySQL so I had a compatibility error.   For example:

`beginningdate` DATETIME NULL DEFAULT convert(datetime,(convert(varchar,datepart(year,getdate())) + ‘-’ + convert(varchar,datepart(month,getdate())) + ‘-’ + convert(varchar,datepart(day,getdate())))),

Since getdate() and datepart() aren’t acceptable functions, I removed the default value for now.  After that all of the data migrated fine except for a few truncated records.  When I move this to production though I’ll be sure to solve that problem.


Jul 9

I hate Windows Firewall

Posted in:Rants | No Comments »

After a brief discussion with Tarken I settled on my new work development server being run on CentOS. For those of you that are unfamiliar, CentOS is the open source community’s free version of RedHat 5 Enterprise. I had initially downloaded the dvd iso image only to realize that my new server doesn’t have a dvd drive. Instead I opted to go the route of a network install. After about an hour of seeing this, I jumped on to irc to see if anyone could help me out with the problem. I was able to ping the booted server, but I wasn’t seeing any network traffic going through.

Finally I realized what was going on, you guessed it, Windows Firewall at some point had opted to turn itself back on. Whether this is an added “feature” for Vista I’m unawares at the present moment. Regardless, after turning it off, the install still started puking running through a web server. Partway through the install I would get a system exception error. Pointing my ftp server to the iso however fixed the problem.


HEY! Did you eat my pickle... or did I?
-Kyle Berg

  • Josh
  • Nothing to Say
  • Plastic Metal
  • Shoe False Fiction