Validating non-US dates in T-SQL

For persons not living in the US, date conversion is an every-day issue. While we mostly work around it by using representations of '20091116' for 16 November 2009, the non-geeks have no idea and enter their dates in their local format. For most of the Western-European countries, this would be a sequence of day, month, year.

It often happens when reading bulk information that dates get treated as text to minimise the amount of conversion errors on the import. I have seen a lot of intricate algorythms to verify the validity of such a string as a date. I have seen people cutting it up by explicitly searching for the separator, storing each part in a different variable, rearranging those variables and then convert the amalgamated strings into a new string which, hopefully, yields a date. I've seen code where the dates get split up, stuck in a table and then rearranged with selects. I believe there is an easier way which simply reads as follows.

 
SET dateformat dmy
 
SELECT 'It''s a date, cap''n!'
FROM tblImport
WHERE ISDATE(someDateField) = 1
 

By using "set dateformat dmy", we tell SQL Server to analyse any possible date by assuming that first part of any date is the day of month, the second is the month and the last part is the year. There are drawbacks, however. You must use either a hyphen or a slash as a separator. You cannot use concatenated date strings or other separators such as periods or blanks.

Still, for us in continental Western-Europe, this solves a lot of problems when reading from bulk imports.


Using SELECT instead of conditionals with variables

You may have found yourself coding something like this in a Stored Procedure.

 
IF @pCode = 'AA' or @pCode = 'AB' or @pCode = 'BA' or @pCode = 'XY'
	SET @actionType = 'single'
ELSE
	SET @actionType = 'combined'
 

You can recode this to SQL to make it more readable.

The second option will be slower - about four times slower - but on my stone-age development system, it still performed 20000 iterations in under 200ms. That's 100000 comparisons per second.

 
SELECT
	@actionType = 'combined'
 
SELECT
	@actionType = 'single'
WHERE
	@pCode in
		(
			'AA',
			'AB',
			'BA',
			'XY'
		)
 

Uservoice.com spam?

Recently, I've been getting spam on a mail address I only use for uservoice.com. What's worse, the amount of spam is about 30 mails a day.

It's weird, because nowhere on the uservoice.com website is your mail address actually displayed or linked. So, either someone who participates in the tweetdeck uservoice discussions had a virus, or uservoice.com has had a privacy leak and all the mail addresses in their database are now being spammed. The latter seems likely because of the high amount of spam I'm getting, which could indicate that spammers believe this address to be recent and valid.

I would like to hear from other people who've had their spam count increase dramatically over the past few weeks and if they can determine why.

Edit: At least 1 other person is experiencing this: http://twitter.com/bjq/status/1784497230


Breaking the privacy law with Computer Futures

Computer Futures is an IT recruitment company. At least, that's what they claim. In fact, they're nothing more than a call-center disguised as a recruitment center. There is no personal contact, no real assessment and no real matching.

In 2003, I applied for a job through Computer Futures. They have kept that information on file for over 6 years without a follow-up call. Any decent recruitment center would have either stopped using that information or place a follow-up meeting to make sure the data is up-to-date. More on the legality of keeping data that long in the last paragraph.

In the meantime, I keep getting job offers that do not concern me. I got job offers for developing in languages or environments that I never worked with and that certainly weren't ever mentioned in my resume. I got job offers stating that the candidate had to live in close vicinity to the offices - which were halfway across the country for me. I got job offers that didn't even mention a job offer, just a description of the company they were "recruiting" for.

I have asked to be removed from their systems several times over the past year. I have done so by writing to the call-center agents that mailed me, by writing to the e-mail address they mentioned in their e-mails and by writing to info@computerfutures.nl. I kept getting mails.

Today, I called them and the person answering the phone couldn't tell me why I hadn't been removed from the system, even though I had used the mail address mentioned in their mails for about four times. Upon asking to be removed, I was told that "I will make sure that you will no longer receive our e-mails". That's not what I asked. I wanted to have my information removed from the system. The call-center agent replied that "I will block everything that I can block". He could not affirm that my data would be permanently deleted. He also wouldn't confirm that they never had face-to-face interviews or that they screened persons by a real-life interview. When I pushed, he asked me if I wanted to have my e-mail removed or if I wanted a discussion. I told him that the latter would be nice since I had some questions about the way they treated me and my privacy to which I got blown off with a "I don't have time for this". Well, thank you! Just another confirmation that Computer Futures doesn't care about you as a person.

Itmight  also be useful to add that Dutch Law states that data concerning job applications should not be held longer than one year after which they have to be destroyed. It looks like Computer Futures is breaking that law. Not only that law, but they're also breaking the OPTA rules which state that everyone should have the right to know what personal data is being kept by an organisation and should have the right to ask for immediate removal of this data from any databases and archives that this organisation stored his or her data in. So, I'm filing complaints with the appropriate government institutes. It'll take time and effort, but that's how tired I am of Computer Futures.


How to reference MSHTML library from C#

This is another typical Microsoft-based development issue. Everyone is writing tutorials and omitting what references need to be set to make the tutorial code work.

Anyway, if you're looking for the MSHTML library, it's a COM reference and it's actually named "Microsoft HTML object library". You need to put using mshtml; in your project to be able to reference it.