BlackCat
BlackCat

Reputation: 2044

Left function in sql server

In table 'Period' there is a column 'Date' ,example data is FEBRUARY 3,2010

Now in where condition Left(Date,3)='Feb' also gives results,Is the Left function case insensitive?

Upvotes: 2

Views: 1441

Answers (2)

Pawel Czapski
Pawel Czapski

Reputation: 1864

You ca also use below query:

select * 
from table_name
where left(lower(column_name),3)  = 'feb'

EDIT: if you don't care about case sensitivity and not sure about collation, if collation is CI (case insensitive) then "lower" is not needed however there is no harm to use it as this function seems to be not expensive one.

Upvotes: 0

John Cappelletti
John Cappelletti

Reputation: 81970

You can set the collate in your query, for example

Declare @YourTable table (Col varchar(25))
Insert Into @YourTable values 
('February'),
('february'),
('FEBRUARY')

Select * 
 From  @YourTable 
 Where left(Col,3) = 'Feb' COLLATE SQL_Latin1_General_CP1_CS_AS

Returns

February

Conversely, if set to SQL_Latin1_General_CP1_CI_AS (insensitive)

You'll get

February
february
FEBRUARY

Upvotes: 5

Related Questions