Blog

20
Nov
2009

bcp BULK INSERT a quote escaped csv file in SQL Server 2005

I was having trouble trying to import a quote escaped CSV file into SQL Server 2005 using BULK INSERT. It kept giving me an unexpected EOF error until I used a format file where I created a dummy start and end column to pick up the initial ” and final \r\n.

For example this format file will import six columns which are all formatted as:

“column1″,”column2″,”column3″,”column4″,”column5″,”column6″

9.0
8
1       SQLCHAR       0       1       ""          0     ExtraField          ""
2       SQLCHAR       0       100     "\",\""     1     ModelId             SQL_Latin1_General_CP1_CI_AS
3       SQLCHAR       0       100     "\",\""     2     QualifyModelId      SQL_Latin1_General_CP1_CI_AS
4       SQLCHAR       0       100     "\",\""     3     MediaAspectCode     SQL_Latin1_General_CP1_CI_AS
5       SQLCHAR       0       100     "\",\""     4     SmallImageFilename  SQL_Latin1_General_CP1_CI_AS
6       SQLCHAR       0       100     "\",\""     5     MediumImageFilename SQL_Latin1_General_CP1_CI_AS
7       SQLCHAR       0       100     "\""        6     LargeImageFilename  SQL_Latin1_General_CP1_CI_AS
8       SQLCHAR       0       100     "\r\n"      0     ExtraField           ""
22
Mar
2009

Installing irssi using macports

To install irssi using macports issue the command:

sudo port install irssi +perl

This will ensure that you get the necessary perl scripting support. Most people using irssi are going to want this.

Note that if you use scriptassist to help you load irssi scripts then you will want some extra perl stuff:

sudo port install p5-libwww-perl

12
Feb
2009

Migrating reporting server database with SQL Server 2005 Standard

If you are moving reporting services to a brand new SQL Server machine (such as setting up a UAT environment or test server) then you may backup and restore the reporting server database from your production machine. You will probably then backup and restore the encryption keys. However you will probably get the error:

“Reporting server can’t be used as part of a scale-out deployment” or something along those lines.

Fear not! Because you aren’t using enterprise you need to remove the key for the old server from the config using:

rskeymgmt -l

and then

rskeymgmt -r

27
Nov
2008

SQL Server Service Broker and Backup Exec

I had a problem today where whenever a full backup of the master database was taken by Backup Exec the Service Broker would say in the SQL Server error logs:

Could not start Service Broker for database id

Google didn’t really know what was going on but I found that if you delete the master4IDR file on the offending server (probably in the default database directory) then do another few backups the problem vanishes.

master4IDR is a copy of the master database that is taken when Backup Exec backs up the database. It is used to do disaster recovery on the server.

29
Jan
2008

What if Facebook could auto-tag uploaded photos?

Facebook could become the ultimate platform for training facial recognition systems. Almost every photo uploaded to the site is of someone. The first thing that you do is to tag the people in the photo, creating a link between the photo and the related person.

But what would happen if the tagging process worked in conjunction with facial recognition technology? Every time a person was tagged in an image you could help the system learn what that person looks like. Eventually the system could become “smart” enough to recognise people on its own.

Auto-tagging photos – it’s the way forward, and you heard it here first!

18
Jan
2008

Check constraints that access the table you are inserting into

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

18
Jan
2008

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.

17
Jan
2008

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)
)

10
Aug
2007

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.

5
Aug
2007

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?

Close
E-mail It