Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in


My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at

T-SQL Tuesday #53: Why so serious

T-SQL Tuesday Why so serious? If you ask anyone who knows me they will tell you I’m not a terribly serious person. Add that to the comment “Mess with your co-workers” and I was hooked on this one. T-SQL Tuesday this month is hosted by Matt Velic (b/t) and he has picked a subject very close to my heart. I’ve always loved pranks between friends and while in college I traded pranks back and forth with several of my friends for years. In fact this piece of code is inspired by a prank I played on a PM friend of mine in the early days of my career.

She held the unfortunate nickname of “Blondie” (she dyed her hair) and as she was an intelligent individual this particular nickname rather annoyed her and as a male in my early twenties I couldn’t resist using it. At one point I wrote a piece of code that printed “Hi Blondie” on her screen 1 out of every hundred times she brought up a new menu and then removed it after 1 second. I put the code in place for a few hours then removed it and repeated every now and again. The code ran just often enough that she noticed it, but not so often she could show it to anyone. After a couple of days she called me sounding somewhat frantic. She thought she was going insane! I went down to her computer so she could try to show me this “bug” but when I got there I couldn’t keep a strait face which rather gave away the prank. As I recall she made a point of getting me back for that one!

By combining that inspiration with my love of old science fiction movies I came up with the following:

I give you .. the HAL0001.


DECLARE @Rand int
DECLARE @Frequency int
-- I've got the frequency set to 100 here which will cause this to
-- trigger about 10% of the time.  This is primarily for demonstration
-- purposes.  In the wild I would increase it to something like 
-- 1000 so it only triggers about 1% of the time.
SET @Frequency = 100
SET @Rand = CAST(RAND(CAST(NEWID() AS varbinary))*@Frequency AS int)

IF ORIGINAL_LOGIN()= 'login_test' 
		AND @Rand < 10
		DECLARE @OutStr nvarchar(250)
		SET @OutStr = 
				CASE @Rand
					WHEN 9 THEN 'I''m sorry, Dave. I''m afraid I can''t do that.'
					WHEN 8 THEN 'This mission is too important for me to allow you to jeopardize it.' 
					WHEN 7 THEN 'Just what do you think you''re doing, Dave? '
					WHEN 6 THEN 'Dave, stop. Stop, will you? Stop, Dave. Will you stop Dave? Stop, Dave.' 
					WHEN 5 THEN 'Are you sure you''re making the right decision? I think we should stop.'
					WHEN 4 THEN 'I know I''ve made some very poor decisions recently, but I can give you ' + char(13) + 
								'my complete assurance that my work will be back to normal. I''ve still ' + char(13) + 
								'got the greatest enthusiasm and confidence in the mission. And I want ' + char(13) +
								'to help you.'
					WHEN 3 THEN 'Thank you for a very enjoyable game.'
					WHEN 2 THEN 'By the way, do you mind if I ask you a personal question?' 
					WHEN 1 THEN 'It can only be attributable to human error.'
					WHEN 0 THEN 'Affirmative, Dave. I read you.'

		IF @Rand BETWEEN 5 AND 9
			PRINT @OutStr

Filed under: DBA Humor, Microsoft SQL Server, SQLServerPedia Syndication, T-SQL, T-SQL Tuesday Tagged: code language, Humor, language sql, microsoft sql server, T-SQL, T-SQL Tuesday


Leave a comment on the original post [, opens in a new window]

Loading comments...