Thursday, December 11, 2008
I was recently wanted to update a SQL Script file that was populating some seed (test) data into a bunch of database tables. I had scripted out the data in the table using a tool and all of the datetime columns were being updated with string values similar to the one below.
I wanted to update all of these to midnight of the current date, so that the data would be current every time the seed data is loaded. To do this I wrote the following T-SQL to put my date into this format in a variable:
DECLARE @CurrentDateString varchar(30)
SET @CurrentDateString = REPLACE(CONVERT(varchar(10), GETDATE(), 102),'.','') + ' 00:00:00'
PRINT 'Current Date: ' + @CurrentDateString
Now, I wanted to update all of the existing string datetime values with my new variable. I had about 75 strings like this in the seed data script file. I fired up Notepad++ and started to work on a Regular Expression to find and the replace all of these entries. Since, writing Regular Expressions is not a common thing for me, after a little googling and some hacking, I came up with the following:
This is probably not the most efficient expression that I could have written, but it go the job done. Anyone have any suggestions for making this better? Thanks!
If your ASP.NET AJAX web site is slow, it may be because you are using UpdatePanels. Please read the article Have you ever wondered why CodePlex is so slow? by Dave Ward. It points out the inefficiencies of using ASP.NET AJAX Update Panels and suggests a better approach with an example. A very good read for any ASP.NET developer who is concerned with performance.