Louis's profileThe SQL Doctor is In (Re...PhotosBlogListsMore ![]() | Help |
|
|
June 07 I love it when this pot gets stirred (stored procedures!)Adam Machanic stirs the old Procs versus Ad-hoc pot with his article To SP or not to SP in SQL Server: an argument for stored procedures over on Red-Gate's Simple Talk site. Admittedly, sometimes it is more fun when I am in disagreement withe the writer, but alas, I agree with everything he says.
I am also excited to see his forthcoming book mentioned (Expert SQL Server 2005 from Apress). I have seen an outline of the book and all I can say is wow. I am not big on self promotion (well, ok, maybe I am...), but from what I know about it, it will be the perfect companion to my book when it comes out and will help you acheive "expert" status.
Edit: The title was "...pot get's stirred?" Oiks! April 24 Why I am now a fan of Newgator.I admit, I had never tried Newsgator, and didn't really think much about it, or really any online news aggregators. I tried google's, but I wasn't 100% convinced that it really gave me what I wanted. I use RSSBandit on my laptop, and will continue to use it for my "bulk" RSS needs (most importantly the PASS Sig Site), but for my "recreational" reading, I will be using Newsgator. Of course, I haven't said why yet have I? Because they had a crash AND, weren't afraid for their employee to tell us why. The best quote was the final paragraph: "But for now - yep, we screwed up. To our customers who were affected - you have my personal apology, and my assurance that we're doing everything we can to ensure this doesn't happen again." In a lot of companies, you couldn't evenm circulate this memo around to the VP of the company, much less the paying customers. What will they think? You are human? Personally I figured that this meant that they cared enough to let people who cared about things know what happened. Corporate honesty is a great quality, if becoming more scarce than a very scarce thing indeed. It impressed me enough that I joined their service and paid the 20 bucks for the premium service so I could have the service on my Pocket PC phone, and so far so good. May 05 Stupid SQL Tricks - Trinomial GeneratorEdit: The function had a bug in it (and probably more) so I upgraded it! It is funny what your love for your family will make you do. Go on vacation to see the world's largest ball of twine, get up an hour early to take a book your child has forgotten, or even write ugly SQL code. Well, we haven't went to se the twine yet, I hope to do that next year, but I did take her a book today, and in fact I have written some ugly SQL code. Why you ask, why indeed. It was taking too long to hand write out practice samples for her to practice the dreaded trinomial. Dreaded not so much because the concept is hard, just that there is many a slip twix the brain and the hand trying to write down answers. So, having some skill working with SQL, I set out to implement some method of creating tests for her to get through the process by doing it a number (a high number!) of times. Here is that code. I warn you, it is ugly. It is not particularly set based, and it is not really a good use of SQL. A few years back, I would have used Visual Basic to code this, but now I have given that up. This really stinks now that I need to learn a CLR programming language to build some objects for SQL Server 2005. Oh well, if you want comments in the code or you find an error, send me an email at drsql@hotmai.com. What I hope to do is build a web page somewhere where you click: Generate Trinomial, and it does this, creates a row in the database, and then waits for you to enter answers. From this the student can take a completely random test, and see what they missed. Who knows if I will ever do this, as I really can't do this with SQL Server only. Here is the function: create function trinomial$display '( ' + case when abs(@secondX) <> 1 then cast(@secondX as varchar(4)) else '' end + + case when @secondX = -1 then '-' else '' end + --x term --no x term ) ------------------------------------------------------------------- select dbo.trinomial$display (-1,1,-1,1,'factored'), Returns: ------------------------------ ------------------------------ Now run the following script and you will get a test, with answer key. --test generator:
declare @firstX int, insert into @trinomialTest(firstX, firstN, secondX, secondN) select 'Multiply','' select 'Answer Guide',''
February 01 Websites and User Groupings. That was fun!One of the things I love best about newsgroups is when a user asks a particularly fun question. Today, a dude named Raterus (Michael) asked for a model of a database: "Here is my problem, I maintain many websites for my company, each have their own set of users. Sometimes, one user needs to be able to access multiple websites (For example...me!). I'm attempting to come up with a table structure that will allow for users and groups which I then can assign to a particular website. All the website names are stored in a table "WebApps", I need to relate the key in that table to a structure that allows the following: I'll have users, also I'll have groups. Groups can contain users, and/or they can contain other groups." I waited, hoping someone else would answer, and nada. Usually at least a smart aleck answer about reading a book (like mine!) but nothing. So I whipped out ERwin and plucked out a database. Unfortunately I forgot the last part of the questions, groups containing other groups. Then I coded that. Fun fun fun. The solution is here. It is not earth shattering, but dang it, when I spend thirty minutes thinking of a solution, I am going to post it here. Heck, some day I might even share my blog address with the world....maybe. January 31 A Thousand Monkeys...As I said yesterday, writing is hard work. So forget that, let's write stupid code. It has often been said that a thousand monkeys with a thousand typewriters given enough time would stumble upon the greatest works in literature. Perhaps. But have you ever thought about just how unlikely that is? I did, and wrote some SQL to figure the chances. So I wrote this bit of code. declare @matchThis varchar(1000) select power(cast(27.0 as real),len(@matchThis)) as predictedNumberOfTries just to calculate it, and then in a minute I will give you the trial and error code behind it. I do 27 because there are 26 characters + spaces. We can easily ignore punctuation as well. So for 'a' the probability is 1 out of 27 that we match. So what about something like: 'this is the tale of our castaways' which is clearly not Shakespeare? 1 out of 1.717E+47, approximately of course. Just to randomly match the four character phrase 'this' is a 1 in 531441 chance. What follows is the whole code I used. It only allows a thousand characters, so you can't put in much more than the Gilligan's Island theme, but it does illustrate a very important point. A thousand monkey's with a thousand typewriters would take millions and millions of years most likely. Could you flio a coin a million times and always end up with heads? What if you had a bunch of atoms, do you think a world might just suddenly appear? I don't want to get off on a rant here, so I will just post the code: set nocount on if object_id('testProbability') is not null truncate table testProbability declare @matchThis varchar(1000), @maxtries bigint select power(cast(27.0 as real),len(@matchThis)) as predictedNumberOfTries
set @keepGoing = 1 while @keepGoing = 1 while @i <= len(@matchThis) insert into testProbability (result) if @matchThis = @holdvalue set @numTries = @numTries + 1 if @numTries = @maxtries It took 1.5 million attempts to match this. At least I didn't have to clean up after a thousand monkeys pooping on typewriters for a million years. |
|
|