old SQL scripts can be a pain

I’m not a fan of debugging other people’s code. I’ve been staring at the same 23 line SQL script for the same 2 hours and I’m wondering how to move forward. The script  hits a Point of Sale database with transactional data and pulls all the sale transactions in a set time period that are account charges. The output is a Fixed Width file sent to our clients so they can payroll deduct purchases from our Point of Sale. It’s adapted from an Access 2000 query so there is some awkwardness.

Lots of substrings and casting.

So I got involved because the SQL script is pulling positive and negative charges and it would be better if it could filter the refund along with the original charge out of the file. It took me 30 minutes to actually pull any data with the script and I’m convinced it’s way off. No way are multiple people are payroll deducting $150,000.00.

I’m tempted to rewrite the thing. I’m also tempted to kick this back. But I’ll probably do it, but it’d be nicer if someone owed me a favor when I got done with it.

UPDATE: I finished this up this week. I created a table variable and inserted transaction numbers where an amount was a negative number. then i added a statement in the main select statement that would select where transaction not in (select transnum from @tablevar). since the refunded amount and the original charge both had the same transaction number, this let me filter out both of them. i’m sure you don’t care. i’m going to go play outside now.

Advertisement

One thought on “old SQL scripts can be a pain

  1. Hey Scott… re-write away if you want. It’s a pain in the ass but I’ve been creating the file by hand every week so if you want to kick it back at me at least there is a process in place to give to the client. And yes, I’ll owe you… Sharon will owe you… and I’ll make sure Jim owes you too!

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s