15 August 2011

How to find out how many decimals are in a column

This is the script to finding out the maximum number for a decimal in a column (how many decimals are there after the decimal point)

SELECT
MAX(LEN(CAST([aFloatColumn]AS VARCHAR(255))) - CHARINDEX('.',CAST([aFloatColumn]AS VARCHAR(255))))

FROM[dbo].[table_1]

27 May 2011

COM Error on PublishForm for Outlook (and you wouldn't believe the solution!)

The problem: an oft file for deployment.
Here is some code in C# which I've copied & pasted into my C# code: (source is in here)

string filename; string location;
_Application olApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
_NameSpace olNs = olApp.GetNamespace("MAPI");
MAPIFolder oInbox = olNs.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
_MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)olApp.CreateItemFromTemplate(location, oInbox);
Microsoft.Office.Interop.Outlook.FormDescription oFormDesc = (Microsoft.Office.Interop.Outlook.FormDescription)oMailItem.FormDescription;


oFormDesc.Name = filename;
oFormDesc.PublishForm(OlFormRegistry.olFolderRegistry, oInbox);
oMailItem.Close(OlInspectorClose.olDiscard);


And this code would fail on the line

oFormDesc.PublishForm(OlFormRegistry.olFolderRegistry, oInbox);

With an error "COMException was Unhandled"

The reason:
The filename (the parameter given) included the string " - ".
So for filename "Broker forms" - pass,
"Broker - forms" -fail.

06 January 2011

Update on a linked table failed

The problem:
"Update or insert of view or function 'function_name' failed because it contains a derived or constant field (#4406)"
in my access database which is linked to SQL server

The reason:
The underlying view is of type "union"

The solution:
change to a single source (not a union select)

17 December 2010

Where did all my values go to?

Or: Mess with values that you enter in a datasheet view.
This is the scenario:
There is a form which contains a sub form which is linked to values in a text box on the form (or to values in a different sub form). The form is displayed as datasheet.
You enter the values you need, all of them are from different linked tables,
and when you go the the next record your values had disappeared and instead you get totally different values!
For example:
the value should be "style" in the outside form
so for the style "myStyle" on the Parent Form the values in the sub form should be:

Bold 5%
Italic 10%
Normal 30%

But when you insert them they're seems to be taking from an existing style somewhere else. When you look in the table in the database, the values had entered correctly, it's just that the display is wrong.


The solution:
Add the id of the linked value to the subform, just hide it. That sort the mess out!

Environment:
Ms-Access 2003, Linked SQL tables.

22 September 2010

Has google docs lost their mind????

Goggle Docs is my favourite word processing application. Simple: I use it for all of my list of changes in the database. Whatever I need to do, I just type it in. I make sure nothing personal/confidential is in there, and I've found that this is the best way to log changes or to write notes to myself that I can access from home or from work.
Today I tried to create a new document for an article that I would like to write, and when I pressed "create new" there was only "from template". Well, I would like to use my beloved "empty document". Oops, you can't do that. Why? Why? Why? Will I have to give up Docs? Will I write my article with pen and paper? Will I be able to read my handwriting afterwords? And why can't I "give feedback"? That's very unlike the expected behavior from a Giant, is it?
I will let you know the answers, whenever I have them...

02 September 2010

String or binary data would be truncated

Scuffling with ‘String or binary data would be truncated’


While the above post was absolutely right about this problem, origins & solution, mine was a bit different:
The solution lay not in the table, but with the table audit. While the description column was defined as [varchar (30)] in the original table, in the Audit table it had to be settled with [Varchar (20)]. Obviously, it wasn't enough: you give the user room to write more in the description column, and they'll use it.

(Yes, of course I had to put the description in the audit table, as the definitions of what's being audit changes all the time)




28 May 2010

The order of columns in a Access Query

If you write a query in Access using the design view, and then move to "datasheet view" and change the order of the columns, the columns' order stays the way you've closed it.
But if you try to "Export to Excel", the order of the columns will be the same as it was defined in the design view. You need to change it in the design view in order to get it in the order you want.