In SQL Server 2005 you can write a check constraint that can include a function call. For example:
ALTER TABLE [dbo].[TestTable1]
ADD CONSTRAINT [TestConstraint1]
CHECK ([dbo].[TestFunction1]([PrimaryKeyColumn1],[Column1],[Column2]) = 0)
However if the function you are calling tests the contents of that table you must be aware that the row you are trying to insert or update will already be in the table. Therefore if part of the test is, for example, duplicate checking or date range checking (in the case of writing scheduling software) then you must pass into the function the primary key of the row you are inserting and add that as a where clause to your function:
CREATE FUNCTION [dbo].[TestFunction1]
(
@param1 int,
@param2 int,
@param3 int,
)
RETURNS bit
AS
BEGIN
DECLARE @ClashesFound int
DECLARE @Result bit
SET @ClashesFound = 0
SET @Result = 0
SET @ClashesFound = (
SELECT COUNT(*)
FROM [dbo].[TestTable1]
WHERE
[PrimaryKeyColumn1] <> @param1
)
IF (@ClashesFound > 0)
SET @Result = 1
RETURN @Result
END
Researchers put circuits on contact lenses, freak out rabbits
Engadget have been writing that researchers have discovered a way to embed electrical circuits including lights and logic into contact lenses. This sounds pretty cool to me and I think it would be great to have a head-up display as you walk around. It could tell you where you are, the time, how to get somewhere, information about the person you are talking to (good for business meetings where I can never remember a persons name) or even allow you to watch TV.
I wonder if Specsavers will be selling them.
SQL code to test a date range against existing ranges in a table
The following slice of code will search a table and return any rows where there is a clash between the date range in the row (ValidFrom and ValidTo) and the date range in the variables (@InTo and @InFrom).
Null dates are treated as either infinite past or infinite future accordingly.
WHERE
NOT (
(@InTo < ValidFrom AND @InTo IS NOT NULL AND ValidFrom IS NOT NULL)
OR
(@InFrom > ValidTo AND @InFrom IS NOT NULL AND ValidTo IS NOT NULL)
)
From my windowpane
I woke up this morning, opened the blinds in my bedroom and was slightly surprised to find over thirty hot air balloons hovering over Bristol.
And then I remembered it was the Bristol International Balloon Fiesta this weekend
Still, nice to wake up to all those hot air balloons. More photos here:
http://gallery.durrans.com/v/events/other/hot-air-2007/
It looks best if you look at the high rez photos.
When was the last time you changed a plug?
I was pondering this question earlier today while I rewired a 4-way adaptor to have a longer lead. When was the last time that I actually had to change a plug. While I was a child I changed plugs all the time. I loved to play around with electrical gadgets that I had acquired through jumble sales and alike. These items often required a plug to be connected and therefore I spent quite a number of weekends messing around with screwdrivers, wire clippers and even in some cases soldering irons.
I remember that in school, both primary and secondary, I was taught how to change a plug. I was taught the colours of the wires inside a cable and how they related to the electrical mains supply. I understood which terminals within a plug these had to be connected to and I knew how to strip the cable to the correct lengths.
These days most electrical items come with a plug moulded onto the wire. It is rare that you have to change a fuse let alone rewire the plug. Before today I really can’t remember the last time that I saw the inside of a plug. Are children even taught, what was once considered a necessary life skill, in schools?
So I ask you, when did you last wire a plug? What colour is the earth wire? Does blue connect to the neutral terminal or the live terminal? Finally, is it the earth or the live terminal that has the fuse?
Mamma Mia at Bristol Hippodrome
Is anyone interested in seeing the touring production of Mamma Mia at the Bristol Hippodrome in December? I am thinking the first weekend of the month, either the Friday or the Saturday.
+1 Brother-in-law
I have aquired myself a brother-in-law. Last week my younger, and only, sister Hannah married Stuart Munn on the Greek island of Rhodes. I flew out to the island to be a guest at their wedding. It didn’t feel very holiday like was I was only there for four nights however it was a lovely ceremony and the island itself, while excessively hot at the moment, was nice.
Stuart managed to leave the rings in the hotel room safe and had to run up many flights of stairs in order to rescue them. In 30’c heat. Just before the ceremony was due to start. Oh how we laughed. He returned saying “Don’t anybody tell Hannah, she will kill me”.
On the day before I was due to fly back to the UK my parents and I visited Rhodes town, looking around the harbour and also the old town. The Knights of St John spent over two hundred years in Rhodes and built a large castle, called the Grand Master’s Palace, next to the harbour. This building, and in fact the entire walls of the old town, were very impressive and you could imagine soldiers having sword fights on the huge marble covered staircase.
Real life Banksy
Wrong side of the tracks
What is loud, fast, very hard, and makes this happen to cars:


A train going over a level crossing when the car shouldn’t have been there. Don’t play on the railways kids!
This car was left in the car park at work by Network Rail. It was recently used as part of their campaign to convince drivers that driving over level crossings when the lights are flashing is generally considered a bad idea.
Human curiosity
As a race us humans never cease to amaze me. Driving south along the M5 motorway this afternoon the radio warned of a serious multi-car accident on the northbound carriageway. As usual this affected the traffic going south as people slowed down to rubber-neck, a term that I dislike but will use. The accident on the other side of the road involved several cars and must have happened at high speed. The police had closed two of the three available lanes, with traffic able to use the third lane to get around the collision. The fire-brigade had just managed to cut someone out of their car, the paramedics had him on a stretcher with their bare feet out in the open air. But this wasn’t what amazed me. I also understand that when a traffic accident occurs it is natural human inquisitiveness for us to want to find out what happened. As I was driving slowly past I noticed that on the hard shoulder, about 200 yards after the accident, a BMW had parked up. The BMW hadn’t been involved in the collision as far as I could see. What I could see was the driver leaning round in his seat holding a video camera. This individual had the audacity to film another person being cut out of the wreckage of their vehicle and attended by paramedics.
Sick.