Using a SELECT statement with a CASE expression SELECT 语句中 CASE 表达式允许在结果集中比较值为基础的替换值。 下面的示例使用 CASE 表达式来更改显示的产品行类别,以使它们更易于理解。 不存在一个值时,文本"不能为销售会显示。 -- Uses AdventureWorks SELECT ProductAlternateKey, Category = CASE ProductLin...
GOSELECTProductNumber,Category=CASEProductLineWHEN'R'THEN'Road'WHEN'M'THEN'Mountain'WHEN'T'THEN'Touring'WHEN'S'THEN'Other sale items'ELSE'Not for sale'END,NameFROMProduction.ProductORDERBYProductNumber; GO B. Using a SELECT statement with a searched CASE expression ...
CASEcan be used in any statement or clause that allows a valid expression. For example, you can useCASEin statements such as SELECT, UPDATE, DELETE and SET, and in clauses such as, IN, WHERE, ORDER BY, and HAVING. Transact-SQL syntax...
CASEcan be used in any statement or clause that allows a valid expression. For example, you can useCASEin statements such as SELECT, UPDATE, DELETE and SET, and in clauses such as, IN, WHERE, ORDER BY, and HAVING. Transact-SQL syntax...
CREATE [ OR ALTER ] { PROC | PROCEDURE } [ schema_name.] procedure_name [ { @parameter data_type } [ OUT | OUTPUT ] ] [ ,...n ] AS { [ BEGIN ] sql_statement [;][ ,...n ] [ END ] } [;] 参数 OR ALTER 适用对象:Azure SQL 数据库、SQL Server(从 SQL Server 2016 (13...
USE tempdb; GO -- UPDATE statement with CTE references that are correctly matched. DECLARE @x TABLE (ID INT, Value INT); DECLARE @y TABLE (ID INT, Value INT); INSERT @x VALUES (1, 10), (2, 20); INSERT @y VALUES (1, 100),(2, 200); WITH cte AS (SELECT * FROM @x) UPD...
USE tempdb; GO -- This statement fails because the PRIMARY KEY cannot accept NULL values -- and the nullability of the COALESCE expression for col2 -- evaluates to NULL. CREATE TABLE #Demo ( col1 INT NULL, col2 AS COALESCE (col1, 0) PRIMARY KEY, col3 AS ISNULL(col1, 0) ); -...
Any Transact-SQL statement or statement grouping as defined by using a statement block. Unless a statement block is used, theIForELSEcondition can affect the performance of only one Transact-SQL statement. To define a statement block, use the control-of-flow keywordsBEGINandEND. ...
{ [ BEGIN ] sql_statement[;] [ ...n] [ END ] } 构成过程主体的一个或多个 Transact-SQL 语句。 您可以使用可选的 BEGIN 和 END 关键字将这些语句括起来。 有关详细信息,请参阅CREATE PROCEDURE (Transact-SQL)中的“最佳做法”、“一般备注”以及“限制和局限”部分。
When a Transact-SQL statement refers to objects that reside in multiple databases, the current database context and the current connection context applies to that statement. In this case, if Transact-SQL statement is in a batch, the current connection context is the database defined by the USE...