Archive for May 18th, 2011

Importing varbinary fields into Excel

May 18th, 2011 admin No comments

I needed to compare two large datasets and find out if they contained the same records.
So I amended the records with a HashByte at the end so I could check if they existed in the other one.
First I imported both queries in Excel with the idea to do a lookup on them.
But a varbinary field is not imported in excel and it will return no error when ommitting a field,
except when the only field is a varbinary field then Excel willl tell you:

No columns that Microsoft Excel can use were returned from this query.

So I had to go back to the Management Studio and join the two sets which was a pain because they were on differend servers.
So much pain I kept trying to find a Excel solution.
All I had to do was convert the varbinary field by making it a parameter in a function which would return a normal varchar.


SELECT [field] FROM [table]

had tot change to

SELECT master.dbo.fn_varbintohexstr([field]) AS [field] FROM [table]



Categories: Excel, SQL Tags: ,

Finally up to date….!

May 18th, 2011 admin No comments

Finally I put back all my post in chronological order. I have a bucket full of ideas for post mainly on PowerPivot, Excel, VBA, SQL Server etc. etc. Probally they will also be posted on the and maybe on some forums because they are not always finalized ideas.

I’m aiming for some feedback and comments….

glad to be back


Categories: Uncategorized Tags:

Checking if a range is sorted with a formula

May 18th, 2011 admin No comments

January 7th, 2011

To test if range B2:B8 is sorted use {=AND(AND(B2:B7<=B3:B8)<>AND(B2:B7>=B3:B8))} in Excel
To enter a array formula ( and get the brackets ) you need to put the formula in without the brackets and press Control+Alt+Enter

thnx to

Categories: Excel, Formulas Tags: ,

Slicers and Filters in Excel 2010 Pivottables

May 18th, 2011 admin No comments

May 28th, 2010

I’m not sure if what I experienced is a bug or a feature….
I created a pivottable in Excel 2010 with slicers and made a selection via the slicers.
So far so good but when I wanted to see the records for a specific datapoint and double click on this point it will give me the complete recordset not taking into account the slicer settings.
But when I put in pivottablefilters for the same fields as the slicers it all works like good old pivottables doubleclicking.

Does anybody know if this is a feature or a bug….?

Risk Management is a game without end

May 18th, 2011 admin No comments

March 16th, 2010

Three actuaries and three accountants are traveling by train to visit a ‘Risk Management Conference’. At the station, the three accountants each buy tickets and watch as the three actuaries buy only a single ticket.

“This looks very risky. How are three people going to travel on only one ticket?”, one of the accountants asks.

“Watch and you’ll see! Take notice of our brand new risk management approach”, one of the actuaries answers.

They all board the train. The accountants take their respective first class seats, but all three actuaries cram into a restroom and close the door behind them.
Shortly after the train has departed, the conductor comes around collecting tickets. He knocks on the restroom door and says, “Ticket, please.” The door opens just a crack and a single arm emerges with a ticket in hand. The conductor takes it and moves on.

The accountants were deeply impressed by the actuarial approach and agreed it was – after all – quite a clever idea without any substantial risk.

So, completely confident and with even more Risk Management skills gained at the inspiring Conference, the accountants decide to copy the actuaries new risk approach on the return trip and save some money (accountants have always been clever with money!). When they get to the station they buy a single ticket for the return trip.

To their astonishment, this time the actuaries don’t buy a ticket at all. “This is reckless, how are you going to travel without a single ticket?”, one of the perplexed accountants asked. “Watch and you’ll see! Take full notice of our latest risk management approach” answered an actuary.

When they board the train the three accountants cram into a restroom and the three actuaries cram into another one nearby. The train departs.

Shortly afterward, one of the actuaries leaves his restroom and walks over to the restroom where the accountants are hiding. He knocks on the door and says, “Ticket, please.”


What conclusions can we draw from this simple story?

Risk Management is a game without end

The effect of Risk Management Conferences is threefold:

Some attendants get smarter
Others get overconfident
Final result: Increasing Risk, instead of decreasing Risk

There’s an old Dutch saying that expresses the danger of increased Risk Management :

“A warned man counts for two”

If we want to reap the fruits of Risk Management, accountants and actuaries have to start working together, instead of struggling and competing each other.

Risk Manager Profile and qualifications
Insight, creativity and integrity are important requirements to become a professional Risk Manager. Unfortunately, this is not enough.

To tackle Risk Management in a company, you need the best potential crook around. One who’s willing to settle his salary and earnings for a little less than he would have earned as a real crook, in return for having a respectable job and not risking to end up in jail. You could call it the Personal Risk management of the Risk manager. Employers that settle for an inferior Risk Manager, know one thing for sure: someday somebody more ‘crooky’ than ‘your risk manager’ will tear your company down!

Categories: Financial Tags:

VBA function for returning Column names, type as a dictionary

May 18th, 2011 admin No comments

February 16th, 2010

I needed the column names of a sql server 2008 table.
So I wrote a function who would return a dictionary with the column names as the key and the type as the item.

‘Set Reference to Microsoft Scripting Runtime
‘Set Reference to Microsoft ActiveX Data Objects 2.7 Library

Function ColumnNames(sConnection As String, sTable As String) As Dictionary

   Dim cConnection As ADODB.Connection
   Dim rsRecordset As ADODB.Recordset
   Dim sSQL As String
   Dim dColumnNames As Dictionary

   sSQL = sSQL & “SELECT AS column_name, AS datatype ”
   sSQL = sSQL & “FROM sysobjects so ”
   sSQL = sSQL & “JOIN syscolumns sc ON = ”
   sSQL = sSQL & “JOIN systypes st ON sc.xtype = st.xtype ”
   sSQL = sSQL & “WHERE so.xtype = ‘U’ ”
   sSQL = sSQL & “AND <> ’sysname’ ”
   sSQL = sSQL & “AND = ‘” & sTable & “‘”

   Set dColumnNames = New Dictionary

   Set cConnection = New ADODB.Connection

   cConnection.Open sConnection
   Set rsRecordset = New ADODB.Recordset
   Set rsRecordset.ActiveConnection = cConnection

   rsRecordset.Open sSQL

   Do While Not rsRecordset.EOF And Not rsRecordset.BOF

      dColumnNames.Add rsRecordset.Fields(0).Value, rsRecordset.Fields(1).Value


   Set rsRecordset = Nothing
   Set cConnection = Nothing

   Set ColumnNames = dColumnNames

End Function

Source file: M_ColumnNames

Categories: Excel, VBA Tags: ,

VLOOKUP returning multiple columns

May 18th, 2011 admin No comments

February 8th, 2010

I use this method for a long time now a just reccently discovered nobody else does.

I’ve got 2 tables, lets call them tbMaster ans tbSlave. Most people use a new vlookup for every column they want to retrieve from tbSlave. What I usually do is use vlookup as an array formula.

For example if I want to get the 4th, 7th and 9th column from tbSlave I select 3 columns in tbMaster and type

=VLOOKUP(tbMaster[[#This Row],[Name]],tbSlave,{4,7,9},0) followed by Ctrl Shift Enter

Besides the normal vlookup disadvantages in my opinion the array solution is better


Categories: Uncategorized Tags:

The risks of stupidity

May 18th, 2011 admin No comments

October 8th, 2009

A general once made a practical observation on the risks of stupidity.

I divide my officers into four classes; the clever, the lazy, the industrious, and the stupid.

Each officer possesses at least two of these qualities.

Those who are clever and industrious are fitted for the highest staff appointments.

Use can be made of those who are stupid and lazy.

The man who is clever and lazy however is for the very highest command; he has the temperament and nerves to deal with all situations.

But whoever is stupid and industrious is a menace and must be removed immediately!



Categories: Uncategorized Tags:

Technical Preview program MS Office 2010

May 18th, 2011 admin No comments

July 15th, 2009

Just got my invitation mail for the Technical Preview program for Office 2010.
I’m gonna dedicate a machine to Windows 7 and Office 2010 because you can’t upgrade
a 64bit Office 2007 system to a Office 2010 system.

Any post will have to wait until I get back from my 2 weeks of vacation starting next friday.


Categories: Uncategorized Tags:

Compagny Culture

May 18th, 2011 admin No comments

May 14th, 2009

Start with a cage containing five apes. In the cage, hang a banana on a string and put stairs
under it. Before long, an ape will go to the stairs and start to climb towards the banana.
As soon as he touches the stairs, spray all of the apes with cold water. After a while, another
ape makes an attempt with the same result-all the apes are sprayed with cold water.

When another ape tries to climb the stairs, the other apes will try to prevent it.

Now, turn off the cold water. Next, remove one ape from the cage and replace it with a new one.
The new ape sees the banana and wants to climb the stairs. To his horror, all of the other apes
attack him.

After another attempt and attack, he knows that if he tries to climb the stairs, he will be
assaulted. Next, remove another of the original five apes and replace it with a new one.
The newcomer goes to the stairs and is attacked. The previous newcomer takes
part in the punishment with enthusiasm.

Again, replace a third original ape with a new one. The new one makes it to the stairs and is
attacked as well. Two of the four apes that beat him have no idea why they were not permitted
to climb the stairs, or why they are participating in the beating of the newest ape.

After replacing the fourth and fifth original apes, all the apes which have
been sprayed with cold water have been replaced. Nevertheless, no ape
ever again approaches the stairs.
Why not? “Because that’s the way it’s always been around here.”

That’s how individual initiative is beaten to death and a company culture begins.

( If you pay peanuts,… you get monkeys )


Categories: Uncategorized Tags: