Skip to main content

Posts

Last post of the year ...

Hi Readers, its just 15 days since I started this blog and as of now there are 300+ visitors from 10+ different countries (India, USA, Kuwait, Italy, Singapore, Canada, Russia, Sweden, Yugoslavia, United kingdom and Malaysia.). I am really impressed by the response :) I would like to take this opportunity to wish you ALL a very HAPPY NEW YEAR. May all your dreams come true in the near future .

Query to display Null values at the bottom ...

Let us assume that a table has following records in it: Sno, FirstName 1, NULL 2, 'Vadivel' 3, 'Sachin' 4, NULL If we write a select statement as follows Select * from sampleTable Order by FirstName The result would be: Sno, FirstName 1, NULL 4, NULL 3, 'Sachin' 2, 'Vadivel' If you want to push all the NULL values to the bottom of the result then use the below the query. Select * from sampleTable Order by  Case    When FirstName Is Null Then 1  Else 0  End, FirstName

Verbatim ...

C# supports 2 forms of string literals. They are, regular string literals and Verbatim string literals. Verbatim string literals begin with @" and end with the matching quote. For instance, strSample = @"F:\sample.xls"; is equivalent to strSample = "F:\\sample.xls";

Researchers find serious vulnerability in Linux Kernel ...

Security professionals took note of a critical new vulnerability in the Linux kernel that could enable an attacker to gain root access to a vulnerable machine and take complete control of it. An unknown cracker recently used this weakness to compromise several of the Debian Project's servers, which led to the discovery of the new vulnerability. Find more about that interesting :) article here

Alternate rows ...

Sometime back in a user group a guy enquired "how to fetch alternate rows from a SQL Server table"? As all of us know there isn't any direct method of doing it in SQL Server. So let me explain couple of work arounds for this. Using Table Variables Declare @tmpTable table (  [RowNum] int identity,  [au_id] varchar(50) NOT NULL ,  [au_lname] [varchar] (40),  [au_fname] [varchar] (20),  [phone] [char] (12) ) -- Filling the row number column of the table variable Insert into @tmpTable select au_id,au_lname, au_fname, phone from authors -- Fetching the alternate records from the table. Select * from @tmpTable where RowNum % 2 0 Using Temp Tables -- Filling the row number column of the temp table Select IDENTITY(int, 1,1) RowNum, au_id,au_lname, au_fname, phone INTO #tmpTable from authors -- Fetching the alternate records from the table. Select * from #tmpTable where RowNum % 2 0 Obviously we could solve this using many ot...

HTTP compression utility

If your sites uses large amounts of bandwidth consider enabling HTTP compression in your IIS. This feature is available from IIS 5.0 onwards. It compresses web pages and content that is downloaded to a browser running on an end users computer and decompresses it on the fly. The server first determines if the end user has a compatible browser (IE 4+, Netscape 4+ etc.,). If the browser is compatible, it then pushes down a compressed version of the page to the client. The customers browser then decompresses the file and displays it. I need to admit that I haven't tried it yet but have read that the feature provided by IIS itself called gzip isn't that stable :( Many say that pipeboost gives us better and reliable functionality. BTW, do you know that google encodes its content and their pages are tiny?

Metabase ...

Are you one among the guys who think Apache is powerful because it is configurable using a config file? then I suggest you to learn about IIS "MetaBase". For your information we can do almost anything we want with IIS by editing the MetaBase!! For instance , we can create virtual directories, stop/ start / pause websites etc., Microsoft provides a GUI utility called MetaEdit , which is somewhat similar to RegEdit, to help you read from and write to the MetaBase. To take full advantage of the MetaBase try out the command-line tool, called the IIS Administration Script Utility (adsutil.vbs) which can be found @ C:\inetpub\adminscripts, or system32\inetsrv\adminsamples. This folder would have lots of other useful administrative scripts as well. That said, the MetaBase is crucial for the functioning of IIS server, so ALWAYS take a backup first before fiddling with it :)

Merry Christmas ...

One shining star to make the world bright, one infant child of that wonderful night, one little prayer for those we hold dear, to bless you @ Christmas and may the peace and joy of the holiday season be with you all throughout the coming year..... (its December 24, 10:35 PM here in India)

C# Refactory ...

C# Refactory is a new tool which enhances VS.NET IDE. Full integration with the IDE allows for quick-access to important refactorings such as Extract Method - simply highlight the code you want to move, then invoke the Refactoring interface to quickly and reliably re-shape your code. 1. Provides useful refactorings. 2. Reliably improves code design. 3. Increases individual and team productivity. 4. Improves the quality of the application development process. 5. Removes the time-consuming and error-prone task of rewriting or refactoring by hand. Download the evaluation copy here and test it for yourself :)

Running number !!

This is one of the question a senior DBA asked me in an interview. Let me explain the question which is really interesting (at least for me :) ) Sample table: Table1 ID, Name 1, aaa 2, aaa 3, aaa Sample table: Table2 ID, Name Null, bbb Null, bbb Null, bbb Required result ID, Name 1, aaa 2, aaa 3, aaa 4 , bbb 5 , bbb 6 , bbb Hmm actually as I was then a Project leader I have lost touch with code :) so it took some time before I answered him properly. At last the query which I wrote is as follows: Select a.[ID], a.[Name] from Table1 a   Union    select distinct a.[ID] + (Select max(ID) from Table1), b.[Name] from Table1 a, Table2 b order by a.[ID]

Doing case sensitive searches

As we know, by default SQL Server installation (6.5/7/0/2K) is case insensitive. What does that mean? The DB would consider the string "VADIVEL" & "vadivel" as same. Perfect! But what if we want to do a case sensitive search in a database. i.e., we want to search for a string "SMART" (Note all characters should be capitals/upper case). If we do a normal select query as shown below it won't work because as said earlier SQL Server installation by default is case insensitive Select * from testTable where testField = 'SMART' In order to overcome this situation, we need to select binary sort order (or) collation while installing SQL Server. After that one way is we need to convert the strings into binary and then compare. Since, 'S' and 's' have different ASCII values, when you convert them to binary, the binary representations wouldn't match and you could get case sensitive results. For example, Select * from testTable wher...

Easiest way to add comments to your SQL 2k code ...

If you are using SQL Server (2K) Query Analyzer to create your Stored procedure / Function / View / Trigger etc., then probably the below tip (!!!) might be of use to you. This would be particularly useful to maintain uniformity in commenting the code when more than one developer is working on a project. Step 1 : Create a comment template something like the one I have shown below: /********************************************************************************************** Name             : Name of the SP/Function/View/etc., comes here Parameters    : Details about the parameters should come here. Description     : Give a detailed description about the procedure here Developer      : M. Vadivel (Put your name here :) ) Created Date : Date on which the procedure is created comes here Change History:- Modified By:     Modified Date: ...