Monday, July 16, 2007

Forcing SQL Server to be Case Sensitive in Query Results

Is there a way to force SQL SERVER to be case sensitive in query results?


Yes, Microsoft has an excellent knowledgebase entry concerning this very issue. The knowledgebase article is Q171299.

In summary, there are two solutions to making the query results case sensitive - one concerns the configuration of the server during its installation and the other entails a coding technique.


1. During installation of the server you can select the character set and sort order. The default sort order is case- insensitive. This implies that case is not factored into the value of a character making. 'A'='a',


2. You can obtain case sensitive results by coding your query using the CONVERT function. This " relies on the fact that the actual data is stored in binary form, with each character represented by a unique hexadecimal value. You can use the CONVERT function to convert the data from character format to a string of hexadecimal values." For example, if you wanted to select companies whose name is 'Acl' and only 'Acl' (i.e. Upper first character, and lower case remaining two characters) the following will produce the desired results: SELECT * FROM table1 WHERE CONVERT(binary(3),company)=CONVERT(binary(3),'Acl')


  Anugrah Atreya


Friday, June 15, 2007

The #line Directive

The #line directive tells the preprocessor to change the compiler's internally stored line number and filename to a given line number and filename. The compiler uses the line number and filename to refer to errors that it finds during compilation. The line number usually refers to the current input line, and the filename refers to the current input file. The line number is incremented after each line is processed.

#line digit-sequence "filename"opt

The digit-sequence value can be any integer constant. Macro replacement can be performed on the preprocessing tokens, but the result must evaluate to the correct syntax. The filename can be any combination of characters and must be enclosed in double quotation marks (" "). If filename is omitted, the previous filename remains unchanged.



The #line Directive - Part2 (Intresting Fact)

The .pdb file generated by the compiler contains line number information to allow the debugger to step through source code. In this for blocks of IL code the corresponding source file and line number information is stored. The #line directive makes the compiler change the line number information it puts into this file. There is an understanding between the debugger and the compiler that if the line number of a block of IL is set as 16707566 ( 0xFeeFee) then the debugger will simply step over this block of code. This is utilized in #line hidden and the compiler translates hidden to 0xFeeFee You can try out the following code to see this in action

using System;
namespace LinePreProcDirective
class Program
static void foo()
#line 16707566
#line default
static void Main(string[] args)

The code marked in bold will be skipped over if you try to step through this code in the debugger.


rename_namespace (#import)


The new name of the namespace.
The rename_namespace attribute is used to rename the namespace that contains the contents of the type library. It takes a single argument, NewName, which specifies the new name for the namespace.

To remove the namespace, use the no_namespace attribute instead.


named_guids (#import)

The named_guids attribute tells the compiler to define and initialize GUID variables in old style, of the form LIBID_MyLib, CLSID_MyCoClass, IID_MyInterface, and DIID_MyDispInterface.

Here is the link to msdn