Archive

Posts Tagged ‘case’

SQL / T-SQL CASE SENSITIVE SELECT

June 3, 2009 1 comment


A very simple method to force case sensitivity in a select statement:

SELECT * FROM DBusers WHERE username = ‘AGENT1′ AND password = ‘paSSworD’ COLLATE SQL_Latin1_General_Cp1_CS_AS


The above statement will only return rows where the password value is exactly paSSworD, case specific.


Categories: SQL Tags: , , , , ,

T-SQL – Using CASE In An Update Statement

February 19, 2009 Leave a comment

The following example will update [TABLE] and assign a value to the PRICEBRACKET field based on the value of the pice field:

UPDATE [TABLE]
SET PRICEBRACKET =
CASE
WHEN (price < 5000)
THEN ‘Less Than 5K’
WHEN (price >= 5000 AND price <10000)
THEN ‘Between 5K and 10K’
WHEN (price >= 10000 AND price <20000)
THEN ‘Between 10K and 20K’
WHEN (price >= 20000 AND price <50000)
THEN ‘Between 20K and 50K’
ELSE ‘Above 50K’
END

Categories: SQL Tags: , , , ,
Follow

Get every new post delivered to your Inbox.