String aggregation in SQL server

February 10th, 2005 Ali Moeen No comments

Lets say we have a table with only one varchar column and no more than 5 rows (typically it is a temporary table ), and the requirement is to extract a comma separated list of value of each row like:

row1, row2, row3, row4, row5

It is possible to do that by using a cursor, But cursors are not efficient and they are usually being used when there is no simpler alternative. This script shows how to so that faster and shorter:


-- Create the table and insert values 

Create table #a (name1 varchar (20))
Insert into #a values ('Ali')
Insert into #a values ('Albert')
Insert into #a values ('Alan')
Insert into #a values ('Al')
Insert into #a values ('Alex')

-- Here is the actual script:
DECLARE @SUM varchar(255),@delimiter CHAR(2)
SET @delimiter = ',' -- Can also be: char(13) + char(10)
SET @SUM = NULL
SELECT @SUM = COALESCE(@SUM + @delimiter,'') +  name1 from #a
Select @SUM as Aggregated_String

Here is the result of running the script:

Aggregated_String
—————————-
Ali, Albert, Alan, Al, Alex

Categories: SQL Tags:

My XmlTextReader cheat sheet!

February 7th, 2005 Ali Moeen No comments

I use this little cheat sheet to remember XmlTextReader class details.


Click to see larger size, It is a little big.

Categories: XML Tags:

Horizontal Scroll Bars on IFrame doesn’t wack me anymore!

October 10th, 2004 Ali Moeen 18 comments

I had hard time trying to remove horizontal scrollbar from IFrames that I had on my first page. Then, I found this article on Macromedia site from Jolantha Belik. It explains possible reasons for IFrame’s redundant horizontal scrollbar and their remedies.

Categories: ASP.NET Tags:

Humor: The Top Ten Reasons .NET is Better than COM

September 4th, 2004 Ali Moeen No comments

I had enough from DCOM during COM days. That’s why I like this Humor at TheServerSide.NET:


Humor: The Top Ten Reasons .NET is Better than COM

Categories: .NET Tags:

Effective database schema search by using INFORMATION_SCHEMA views

August 21st, 2004 Ali Moeen No comments

Some times I need to know which stored procedure uses a specific table. I simply use this query:


SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE ‘%TheTableName%’


Similarly, we can use INFORMATION_SCHEMA.COLUMNS view to know which table contains a specific column name

Categories: SQL Tags:

Interviews with Anders Hejlsberg

August 9th, 2004 Ali Moeen No comments
Categories: C# Tags:

Java vs. .NET!

May 3rd, 2004 Ali Moeen No comments

I am more kind of .NET guy, but I always whach how the two technologies compet with each other. To me it’s more like wtching a soccer play! Here are some nice articles:


Categories: .NET, C# Tags:

Read this if you are going to install RedHat Linux on Virtual PC

March 7th, 2004 Ali Moeen No comments

Virtual PC is a great product, but it gave me hard time when I was installing RedHat Linux on it. The problem is the default color resolution on RedHat is 24 bit and Virtual PC cannot handle 24 bit color depth, Therefore it shows a fuzzy screen when you run KDE desktop.


The solution stated in Microsoft kb 824513 can be simplified. Here is my simplified solution:


Solution 1) During the installation, choose customize graphic configuration then choose “16 Bit” as the color depth. This is a snapshot of the screen:



Click to see larger size


Solution 2) After the installation, if the screen is fuzzy, so you can’t read contents. Here are the steps:



  1. Press Left{Control-Alt}-1, Linux switches to the first text terminal
  2. It prompts for login, Login as root.
  3. Edit /etc/X11/XF86Config (like vi /etc/X11/XF86Config)
  4. In the section .., change the DefaultDepth to 16
    Here is a screen shot:


Click to see larger size

Categories: Windows User Tags:

An Extensive Examination of Data Structures

December 16th, 2003 Ali Moeen No comments

These are very nice articles about Data Structure. They remind me school days. It is good to have data structure articles from C# prespective:

Categories: C# Tags:

A sharing violation occured while accessing C:\Inetpub\wwwroot\…

July 7th, 2003 Ali Moeen No comments

When ASP.NET encounters an error and stop during processing a page that opens a data file, any attempt to edit the file pops up the above error message! That means some process have the data file open and doesn’t allow you to touch it.


The solution is murdering ASP.NET worker process, aspnet_wp.exe, through Windows Task Manager. The worker process starts again upon next page request; however the application will be restarted. That is all session variables will be lost!

April 2007 Update: Today I use Ulocker to take care of all annoying sharing violation pop-ups!

Categories: ASP.NET Tags: