Thursday 8 April 2010

Differences between a static member function and non-static member functions

The differences between a static member function and non-static member functions are as follows.
  • A static member function can access only static member data, static member functions and data and functions outside the class. A non-static member function can access all of the above including the static data member.
  • A static member function can be called, even when a class is not instantiated, a non-static member function can be called only after instantiating the class as an object.
  • A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual
  • A static member function cannot have access to the 'this' pointer of the class.
The static member functions are not used very frequently in programs. But nevertheless, they become useful whenever we need to have functions which are accessible even when the class is not instantiated.

How can I make my SQL queries case sensitive?

CREATE TABLE mytable
(
mycolumn VARCHAR(10)
)
GO

SET NOCOUNT ON

INSERT mytable VALUES('Case')
GO

SELECT mycolumn FROM mytable WHERE mycolumn='Case'
SELECT mycolumn FROM mytable WHERE mycolumn='caSE'
SELECT mycolumn FROM mytable WHERE mycolumn='case'

You can alter your query by forcing collation at the column level:

SELECT myColumn FROM myTable
WHERE myColumn COLLATE Latin1_General_CS_AS = 'caSE'

SELECT myColumn FROM myTable
WHERE myColumn COLLATE Latin1_General_CS_AS = 'case'

SELECT myColumn FROM myTable
WHERE myColumn COLLATE Latin1_General_CS_AS = 'Case'

-- if myColumn has an index, you will likely benefit by adding
-- AND myColumn = 'case'