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
The CASE keyword is used as a conditional operator that considers a value, examines it, and acts on an option depending on the value. The formula of the CASE statement is:
CASE Expression
WHEN Value1 THEN Result
WHEN Value2 THEN Result
WHEN Value_n THEN Result
END
In the following example, a letter that represents a student is provided. If the letter is m or M, a string is created as Male. If the value is provided as f or F, a string is created as Female:
DECLARE @CharGender Char(1),
@Gender Varchar(20);
SET @CharGender = 'F';
SET @Gender =
CASE @CharGender
WHEN 'm' THEN 'Male'
WHEN 'M' THEN 'Male'
WHEN 'f' THEN 'Female'
WHEN 'F' THEN 'Female'
END;
SELECT 'Student Gender: ' + @Gender;
GO
source : http://blogs.msdn.com/sharepoint/default.aspx
Minggu, 15 Februari 2009
Langganan:
Postingan (Atom)