zxg58 发表于 2015-7-5 00:23:57

SQL Server-流程控制 2,If...Else 语句




ylbtech-SQL Server:SQL Server-流程控制 2,If...Else 语句


  SQL Server 流程控制中的 If...Else 语句。




1,If...Else 语句






1 --=============================================================
2 -- 1, If...Else语句
3 -- Desc:If..Else语句是条件判断语句
4 -- author:ylbtech
5 -- pubdate:10:39 2012/12/15
6 --=============================================================
7 go
8
9 go
10 --=============================================================
11 -- 2,Syntax
12 --=============================================================
13 If Boolean_expression
14 {sql_statement|statement_block}
15 [Else
16 {sql_statement|statement_block}]
17 --Remark:该语法解释为:当Boolean_expression为真时,执行If语句块里的语句,否则执行Else语句块里的语句。
18
19 go
20 --=============================================================
21 -- 3,Example
22 -- Desc:查看产品表中名称为“Gorgonzola Telino”的商品单价是否低于20元,将结果输入来。其代码如下。
23 --=============================================================
24 use Northwind
25 go
26 Declare @price money
27
28 select @price=UnitPrice from Products where ProductName='Gorgonzola Telino'
29
30 if @price
页: [1]
查看完整版本: SQL Server-流程控制 2,If...Else 语句