Gerard's codebase

This is a personal repository of code snippets and information.

Over the years I have generated lots of little sub programs and stored away acres of useful code snippets. The problem is always to locate them.

Even more time wasting is forgetting how to do simple things when you havnt developed in an environment for a few years (or even a few months)

My new years resolution is to start putting them up in a common place as I produce them. (thanks google)

They are handy for me and, with a bit of a clean up and documentation, they might be handy for others if they wander in here.

Gerard 2008

Sunday, July 5, 2009

Return File name from path

Always handy - never there when you need it. A simple recursive function to return the file name from the full path


Private Function GetFilenameFromPath(ByVal strPath As String) As String
' Returns the rightmost characters of a string upto but not including the rightmost '\'
' e.g. 'c:\winnt\win.ini' returns 'win.ini'

If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
End If
End Function

Tuesday, April 14, 2009

List Object in SQL Db - Specific Examples

The generic SQL found here can be tweaked to do almost anything


The following are more specific examples
-- This snippet searches for columns named like %product% 
SELECT
o.name AS TableName,c.*
FROM
sysobjects AS o
INNER JOIN syscolumns AS c
ON c.id = o.id
WHERE
(o.type = 'U' OR o.type = 'S')
AND c.name LIKE '%product%'

Thursday, April 2, 2009

Deleting Restoring Databases

I keep forgetting this and it cost me time as the job runs forever and will not cancel.
With logshipping you sometimes need to delete a restoring database that has failed.
Remember that you need to uncheck the "delete backup and restore" checkbox