Thursday, August 19, 2010

SQL fun

You ever have one of those days?  This one stretched out for about a week.  Over and over again, trying to solve a very odd problem.  Seems like a certain type of look up was failing, but only on a single database.  Check the stored procedure for look up, looked fine.  Replicated the process to populate the look up, worked fine, for a moment, then suddenly didn't work anymore.  WTH?!?

Here's my script to add a value to the table.  Keep in mind that I didn't have direct access to the table itself, I'd assumed the look up query was failing, and ran repeated tests against that.  Anyway, to add a value to the table:

delete from lookUpTable where AccountID = @AccountID or @LookupID = @LookupID

insert into lookUpTable (AccountID, LookupID) values (@AccountID, @LookupID)

I looked over this query (quickly, mind you, I was still convinced the look up itself was failing).  Then I asked to look at the table.  If you read the above query and said, "You found only one row, right?" cookie for you, if not, look at the above script one more time.  The first time someone who wasn't me looked at it they pointed out the problem immediately, but it was kicking me around for what felt like forever.  Always good to have another pair of eyes.

In my defense this stored procedure had been changed several times, I'd look at it and go "yep, looks right" and examine the look up s.p. again for issues.  And lookUpTable was being cleared over and over again while we tested.

No comments:

Post a Comment