MSSQL – How To Output To A File

There is a very, very simple one liner within MySQL to dump the results of a query into a text file. Nothing so simple exists within MSSQL, but there are fairly easy workarounds. Using BCP, one can use the xp_cmdshell to pass the results into the desired file.

use DatabaseName
go

declare @FileName varchar(50)
declare @bcpCommand varchar(2000)

set @FileName = REPLACE(‘c:\temp\bcp\postcodes_’+CONVERT(char(8),GETDATE(),1)+’.csv’,'/’,'-’)

set @bcpCommand = ‘bcp “select left(postcode,4), count(*) from DatabaseName..TableName where customersequence = 0 group by left(postcode,4) order by count(*) desc” queryout “‘
set @bcpCommand = @bcpCommand + @FileName + ‘” -U username -P password -c’

EXEC master..xp_cmdshell @bcpCommand

This dumps a load of postcode information, based on usage, into a csv file in c:\temp\bcp. What the query is doesn’t really matter, just the bcp commands to provide us with the results in a file of our choosing (.csv in this case).

The @FileName command simply appends the current date to the file in order to keep track of queries.

Todmorden Tri

Well I had a whale of a time. My provisional time is 1hr14, that is from starting the stop watch 5 seconds before the swim and stopping it as I crossed the run finish line. The transitions went perfectly, I genuinely don’t think I could have done any better/faster.

The cycle was incredible – a four mile climb to start with which hurt a lot (I don’t have any hills to practice on), and then a steep down hill on which, according to my cycle computer, I clocked a top speed of 44.5mph!

I then ran a ~22 min 5k which ordinarily would be terrible, but again it was hilly (where do they get those from up north anyway?) but I’m happy with it on a recovering leg and for a first Tri.

What a great experience, thoroughly enjoyed it – I will definitely be doing more.

Triathlon List

Despite something in my brain screaming restraint, I’m signed up for four Triathlons now. Though the Ely place isn’t confirmed as they have a small field, I’m registered for the other three.

  • Todmorden Sprint Tri – 4th July
  • Box End Sprint Tri – 11th July
  • South Coast Classic Olympic Distance – 14th August
  • Ely Sprint Tri – 5th September

Todmorden Sprint Try

So I’ve entered my first triathlons in the upcoming months. I’m doing the South Sea Classic in August (1.5km/40km/10km swim/bike/run) and as means of preparation decided that looking for an earlier event would make good sense.

And so I found the Todmorden Sprint Triathlon (400m/20km/5km). My aim is to try, nothing else – get experience of the transitions, see if I can get round and properly condition each leg so that I don’t blow up on the run – a distinct danger as I’m likely to give it some on the cycle. This is on the 4th of July, I’d like to think I’m prepared – the distance is easy, I’ve practised transitions. I’m hoping to finish in a competent first-go time.

The same has to be said for the SSC in August (14th), it’s a much longer distance, especially the swim which is my weakest discipline. And it is a wetsuit swim in the sea, which will be a real challenge for me. Still, looking forward to finishing and getting round in at least a competent time, with eyes on the bigger prize of Ironman distance next year with any luck.

Ideal Landscapes Ltd

Over a month long of chasing has gotten me nowhere.

We had some work done to our garden, namely a tree to be taken down, the root to be taken away, and the tree to be logged into firewood, with the ground being levelled.

The word undertaken by Ideal Landscapes (referred to as “Ideal” from here on in) was far from ideal. A catalogue of problems arose after allowing these people to undertake work for us. I guess I should start at the beginning, which is more then “Ideal” could do, as they undertook the work three days early. This wasn’t a massive problem aside from the fact that we had warned our neighbours of the impending work date.

Whilst the tree was indeed taken down, it was also taken away, leaving us without the firewood. Now the tree was between 45-50 feet hight, and around 1.5-2 feet thick at the bottom. Admittedly the wood would have required drying, but that is exactly what we intended to do. Estimates for this amount of firewood amount to anywhere between £200-£500 that I’ve seen so far.

Next, they did indeed take the root out, or some of it. I understand it can be hard to properly get rid of roots, so that is bye the bye I suppose. However, they were also to level the ground, something we spent the best part of a week doing.

“Ideal” left refuse (that they were contracted to take away) not only on our garden, but on our neighbours garden. Fortunately she has been cool about the whole situation, and whilst we gave her a very nice bottle of wine to say thank you, we should probably make that a few more.

And as a final insult, “Ideal” needed to bring in a digger to get the root out, and so had to take down the fence at the bottom of our garden. Far from safely re-attaching it, they simply cut the bolts holding it to the fence posts and left us with a future repair bill.

We paid “Ideal” £475 (inc VAT) for this privilege.

So we sent a letter, detailing why we were unhappy and what we wanted doing. No response. I phoned the number, which re-directs to a mobile, and after several attempts finally got through. Cue apologies, several promises to bring the wood round and sort the fence. Nothing about levelling the ground or getting rid of the rubbish, but I figured that was the best course of action. Of course nothing happened.

I then opened a case with Consumer Direct, the public facing arm of the Office of Fair Trading & Standards, who advised me to send a letter again, recorded, citing the Sales of Goods & Services Act.

So we sent another letter, this time by recorded delivery. This is where things started to get odd. First of all, Royal Mail said they couldn’t deliver it as no one was there to sign. Then a few weeks ago, we had an answer phone message from someone who said that they had lived at the address “Ideal” gave us, and that they had done so for over a year.

A few things strike me as odd here: firstly why would you sign for mail that was addressed to someone you know used to be at your address, surely you would tell the postman and send it back? Secondly opening mail addressed to someone else is an offence, and thirdly, if this had been happening for over a year why would you still be opening that mail to send it back to the sender? And fourthly, they managed to get my first letter, so why not the second?

I’ve spoken to the Insolvency Register to find out that they are a Ltd company and are not insolvent, so far so good.

And so I’ve been trying to find out where this company is actually based. I looked up the company on companieshouse, and then contacted the south Cambridgeshire District council to try and find out what type of property is registered at the address “Ideal” gave us. Due to Data Protection regulations however, they couldn’t help me. So I contacted the Valuation Office Agency, who obviously couldn’t tell me who payed council tax on the property, but that the premises is registered as ‘Domestic’.

As an aside – Ideal Landscapes by Design Ltd is registered to the above address on CompaniesHouse.gov.uk. It is a legal requirement to keep these details up to date, and an offence not to inform the register that your details have changed. So one way or another, “Ideal” have broken the law.

Sadly, this is where my trail runs out, and Consumer Direct can help me no more.

Edit:
I guess I could turn to Anne Robinson..

I can’t even tell dear old Anne about it because the Watchdog “Your Story” form is broken. Typical.

Google – ‘We Screwed Up’

Yes folks, it’s true, the great God Google is fallible. The only problem being that they have seriously broken the law this time.

What really irritates me is that Sergey Brin is merely exercising in damage limitation. This would have come out sooner, rather then later, if Google hadn’t taken the step to admit it publicly, and things would have been a lot worse for the bastardscompany.

They say they’ll now delete all the data they collected. Right, who’s going to watch them do it?

This kind of thing is illegal, and anyone else doing it would face massive fines and a criminal record, within the UK, but because it’s Google, I’m betting they’ll get away with it.

Roy Hattersley In The Times

Praised Gordon Brown in this article in the times.

Evangelical fervour and reformist zeal: the very qualities that drive the extremist, the obsessive that will brook no other view but his own. Indeed Brown possesses these without qualification and he would bend any means to his end. He taxed and taxed to fund his ‘vision’ and when this was not enough he borrowed and pledged the future. He bloated the public sector and let slip the reins on immigration to ensure his future constituency. Like other obsessives he lived in denial of any error of his own, seeing always the fault in global markets, disloyal colleagues, biased media: he could not be wrong. He pointed the finger at privilege, accusing it as self-serving, dishonest and incompetent by definition; the very characteristics he himself displayed and that is why the Duffy slip so damaged him.

His legacy is debt almost beyond comprehension and a society deeply divided and uncertain of its future. His passion has invoked a passion also and he will be remembered, but not as the writer so fondly imagines. He is a monument to ruthless ambition for self and a warning against the Socialist’s longing to control the lives of his fellow citizens. Let us be done with him and may the memory of him remind us to be watchful that our government remains our servant, not becomes our master.