Archive for January, 2010

How to use the undocumented stored procedure sp_msforeachtable to add a column to all tables in a database ?

There are two examples, in both I add a column to each tables except the spnet membership tables.
Example :
Add the “CreatedDate” column to all tables :

print ‘Add [CreatedDate] Column for each user table’

EXEC sp_msforeachtable

– add column
exec(”
declare @tableName as nvarchar(max)
set @tableName = ””_?_””

IF (CHARINDEX(””aspnet_””,@tableName) = 0) — no aspnet membership
BEGIN
IF [...]

More »

Zeros and strings manipulation in Tsql

How do I convert an int to a zero padded string in T-SQL?
Let’s say I have an int with the value of 1.
How can I convert that int to a zero padded string, such as “00000001″?

DECLARE @iVal int
SET @iVal = 1
select REPLACE(STR(@iVal,8,0),’ ‘,’0′)

result is “00000001″
And the inverse :
Let’s say you have a string “0000000120345FER” and [...]

More »

A few lists …

The Joel Test: 12 Steps to Better Code
Top 10 Things That Annoy Programmers
10 Programming proverbs every developer should know
101 Ways To Know Your Software Project Is Doomed
Top 100 Blogs for Developers
–> Pragmatic Software Development Tips

More »

Copy datatable’s row to an other datatable’s row

This method perform a row copy with a few checks

public static void CopyRowToAnOther(DataRow row, DataRow anOtherRow)
{

if (row == null || row.Table == null
[...]

More »

Don’t repeat your common CSS between your different themes

To fully understand this article, you need an Asp.Net Themes system knowledge
The case :
You have an application with a CSS layout, and a few themes.
There is just a little change between the different themes, by example you change only the color scheme.
A solution to do that is to repeat all CSS files in all your [...]

More »