IF测试可以嵌套在另一个IF或之后ELSE。 嵌套级数的限制取决于可用内存。 示例 SQL IF DATENAME(weekday, GETDATE()) IN (N'Saturday', N'Sunday')SELECT'Weekend'; ELSESELECT'Weekday'; 有关更多示例,请参阅ELSE (IF...ELSE)。 示例:Azure Synapse Analytics 和
IF 1 = 1 PRINT 'Boolean expression is true.' ELSE PRINT 'Boolean expression is false.'; 下面的示例具有一个布尔表达式(),该表达式为1 = 2false,因此输出第二个语句。 SQL IF 1 = 2 PRINT 'Boolean expression is true.' ELSE PRINT 'Boolean expression is false.'; GO ...
IFboolean_expression{sql_statement|statement_block} [ELSE{sql_statement|statement_block} ] Nota Para exibir a sintaxe do Transact-SQL para o SQL Server 2014 (12.x) e versões anteriores, confira aDocumentação das versões anteriores. ...
IF 1 = 1 PRINT 'Boolean expression is true.' ELSE PRINT 'Boolean expression is false.'; The following example has a Boolean expression (1 = 2) that is false, and therefore prints the second statement. SQL Copy IF 1 = 2 PRINT 'Boolean expression is true.' ELSE PRINT 'Boolean expre...
The Transact-SQL statement that follows an IF keyword and its condition is executed if the condition is satisfied: the Boolean expression returns TRUE. The optional ELSE keyword introduces another Transact-SQL statement that is executed when the IF condition is not satisfied: the Boolean expression ...
AnIF...ELSEconstruct can be used in batches, in stored procedures, and in ad hoc queries. When this construct is used in a stored procedure, it's usually to test for the existence of some parameter. IFtests can be nested after anotherIFor following anELSE. The limit to the number of...
IF 1 = 1 PRINT 'Boolean expression is true.' ELSE PRINT 'Boolean expression is false.'; The following example has a Boolean expression (1 = 2) that is false, and therefore prints the second statement. SQL Copy IF 1 = 2 PRINT 'Boolean expression is true.' ELSE PRINT 'Boolean expre...
IF 1 = 2 PRINT 'Boolean_expression is true.' ELSE PRINT 'Boolean_expression is false.' ; GO B. Using a query as part of a Boolean expression The following example executes a query as part of the Boolean expression. Because there are 10 bikes in the Product table that meet the WHERE ...
DBCC results for 'model'. CHECKDB found 0 allocation errors and 0 consistency errors in database 'master'. DBCC execution completed. If DBCC printed error messages, contact your system administrator. 如果指定了DBCC CHECKDB,则ESTIMATEONLY返回以下结果集。
运行时编译的 Transact-SQL 语句可能会向恶意攻击公开应用程序。 使用sp_executesql时应参数化查询。 有关详细信息,请参阅SQL 注入。 Transact-SQL 语法约定 语法 SQL Server、Azure SQL 数据库、Azure SQL 托管实例、Azure Synapse Analytics 和 Analytics Platform System(PDW)的语法。