I found a post on the Microsoft Forums that I had a bit of fun with.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2941690&SiteID=1
My response shows how to find a fixed length phrase in a document that start with certain words.
Friday, 28 March 2008
Monday, 24 March 2008
SQL2008 - Create Table Based on User-Defined Table Type
Table types are really neat. Mind you, one of the features I would love to see is the ability to create a table based on a table type (i.e. CREATE TABLE LIKE ).
Imagine this scenario, you define all your table types up front with extended property "TableType" i.e. (each Table Type will have whatever columns it needs - but will have extended property "TableType")
"TableType" 1 = Lookup table,
"TableType" 2 = Lookup table,
"TableType" 3 = Fact table,
"TableType" 4 = Dimension table
(Assuming a data warehouse here.)
... OR ...
Table Type 1 = Lookup table,
Table Type 2 = Data table,
Table Type 3 = History table
(Assuming an OLTP system)
You would be able to define the table types in one location, and the extended properties and indexes (optionally) could be propagated to the tables you create based on those types. I picture it almost like inheritance, you could create a table based on a table type - then extend the table type to include additional properties.
Advantages of this would be that you could apply manageability rules (similar to what VS2005 has and standard sets of unit tests to your tables that are created based on such types). Until such a time as this becomes reality, here are some workarounds. (Of course, you will have to do some work to propagate extended properties from tables/table types that you inherit from.)
Imagine this scenario, you define all your table types up front with extended property "TableType" i.e. (each Table Type will have whatever columns it needs - but will have extended property "TableType")
"TableType" 1 = Lookup table,
"TableType" 2 = Lookup table,
"TableType" 3 = Fact table,
"TableType" 4 = Dimension table
(Assuming a data warehouse here.)
... OR ...
Table Type 1 = Lookup table,
Table Type 2 = Data table,
Table Type 3 = History table
(Assuming an OLTP system)
You would be able to define the table types in one location, and the extended properties and indexes (optionally) could be propagated to the tables you create based on those types. I picture it almost like inheritance, you could create a table based on a table type - then extend the table type to include additional properties.
Advantages of this would be that you could apply manageability rules (similar to what VS2005 has and standard sets of unit tests to your tables that are created based on such types). Until such a time as this becomes reality, here are some workarounds. (Of course, you will have to do some work to propagate extended properties from tables/table types that you inherit from.)
1. Create Table based on another table
SELECT top 0 * INTO mynewtable from mytable
2. Create Temporary Table based on another table
SELECT top 0 * INTO #mynewtable from mytable
3. Create Table based on table type
DECLARE @mytable MyTableType
SELECT TOP 0 * INTO mynewtable FROM @mytable
Thursday, 20 March 2008
DataSets, Xml Schemas, and Excel - Oh My!
I have created another article on code project detailing the transformation power of the dataset. It isn't just for getting data from the database. You can find it here.
Friday, 14 March 2008
Xml String Browser
I created my first web article. The title was "XML String Browser (just like Internet Explorer) using WebBrowser Control". You can find this article on Code Project by clicking on the following link. It was great fun to do and I hope to write a few more articles. I was motivated to do this because the .NET Web Browser control does not support pretty rendering of XML strings or XML Documents (unless you are viewing XML files).
Thursday, 6 March 2008
Execute cmd/bat from VS2005

I haven't blogged for a while. Unfortunately, I have been really busy. Here is a helpful tip that I discovered a while ago .... It is an incredibly handy one .
1. First, you need to go to Tools->External Tools in the Visual Studio IDE.
2. Then, add a new one with the settings depicted in the picture below.
I would be interested to know if people find this one as useful as I have. I have been using it for a number of purposes (including executing various Nant scripts).
Also, An important note - you have to Customize the context menu before you can use the Execute Command External Tool. This is done by:
1. Clicking on Tools->Customize and select Context Menu.
2. Drag and drop the External Tool to the Project Items -> Project Item context menu.
Friday, 12 January 2007
More on Regular Expression patterns
Regular expression patterns are powerful. I have been recently using Log4Net to log system activity and created a regular expression similar to the one below to allow multi-line text log parsing.
Sample Text:
2007-01-01 00:00:00 Test log message
Another line
Yet one more line
2002-01-01 00:01:01 Another test log message
Regular Expression Pattern:
^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})[ ]*((?:(?!\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*(?:(?!\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*\n?)*))
The above regular expression pattern will capture Date and parse the LogText where the additional lines don't begin with the Date.
Sample Text:
2007-01-01 00:00:00 Test log message
Another line
Yet one more line
2002-01-01 00:01:01 Another test log message
Regular Expression Pattern:
^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})[ ]*((?:(?!\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*(?:(?!\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*\n?)*))
The above regular expression pattern will capture Date and parse the LogText where the additional lines don't begin with the Date.
Tuesday, 2 January 2007
Happy New Year!
It is a New Year. It is a time to look ahead and time to look behind. Back to a favorite topic of mine. Regular expressions. Today I discovered a cool way to do selective search and replace on a substring. Take the following example:
Sample Text:
i before e, except after c
Man very early made jars stand up! Nearly perfect
Regular Expression Pattern
(?<=^[^,!]*)e
Regular Expression Replace String
E
Use a tool like Expresso to work with regular expressions. Other free tools are RegEx Designer or The Regulator. The result you will get when you run the replace with the above Regular Expression is as follows:
i bEforE E, except after c
Man vEry Early madE jars stand up! Nearly perfect
Notice the selective replacement of e with a capital E. How does this work? Take a look at the analysis for the above regular expression pattern:
Match a prefix but exclude it from the capture. [^[^,!]*]
^[^,!]*
Beginning of line or string
Any character that is not in this class: [,!], any number of repetitions
e
What this effectively does is look behind any letter e in a string that is not preceded by a , or !. In effect, that allows us to limit the replacement to all occurrences of e that occur before a , or !. Pretty cool, no?
Sample Text:
i before e, except after c
Man very early made jars stand up! Nearly perfect
Regular Expression Pattern
(?<=^[^,!]*)e
Regular Expression Replace String
E
Use a tool like Expresso to work with regular expressions. Other free tools are RegEx Designer or The Regulator. The result you will get when you run the replace with the above Regular Expression is as follows:
i bEforE E, except after c
Man vEry Early madE jars stand up! Nearly perfect
Notice the selective replacement of e with a capital E. How does this work? Take a look at the analysis for the above regular expression pattern:
Match a prefix but exclude it from the capture. [^[^,!]*]
^[^,!]*
Beginning of line or string
Any character that is not in this class: [,!], any number of repetitions
e
What this effectively does is look behind any letter e in a string that is not preceded by a , or !. In effect, that allows us to limit the replacement to all occurrences of e that occur before a , or !. Pretty cool, no?
Subscribe to:
Posts (Atom)