Microsoft SharePoint Team Blog
The official blog of the Microsoft SharePoint Product Group
SQL Expressions
Logical Comparisons
Introduction
For your databases, you can create expressions that represent a combination of values, variables, and operators. To support expressions, Transact-SQL provides operators other than, or in addition to, those we saw in Lesson 2.
A comparison is a Boolean operation that produces a true or a false result, depending on the values on which the comparison is performed. A comparison is performed between two values of the same type; for example, you can compare two numbers, two characters, or the names of two cities. To support comparisons, Transact-SQL provides all necessary operators.
Conditional Statements
Introduction
CASE...WHEN...THEN...ELSE
In most cases, you may know the only types of value that would be submitted to a CASE statement. In some other cases, an unpredictable value may be submitted. If you anticipate a value other than those you are aware of, the CASE statement provides a "fit-all' alternative by using the last statement as ELSE. In this case, the formula of the CASE statement would be:
CASE Expression
WHEN Value1 THEN Result
WHEN Value2 THEN Result
WHEN Value_n THEN Result
ELSE Alternative
END
The ELSE statement, as the last, is used when none of the values of the WHEN statements fits. Here is an example:
DECLARE @CharGender Char(1),
@Gender Varchar(20);
SET @CharGender = 'g';
SET @Gender =
CASE @CharGender
WHEN 'm' THEN 'Male'
WHEN 'M' THEN 'Male'
WHEN 'f' THEN 'Female'
WHEN 'F' THEN 'Female'
ELSE 'Unknown'
END;
SELECT 'Student Gender: ' + @Gender;
GO
source : http://blogs.msdn.com/sharepoint/default.aspx
Minggu, 15 Februari 2009
Langganan:
Postingan (Atom)