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<$20 31 Print 'UnitPrice less than $20' 32 Else 33 Print 'UnitPrice greater than $20' 34 35 36 go 37 --============================================================= 38 -- 4,Operation result 39 --============================================================= 40 --UnitPrice less than $20
![]() |
作者:ylbtech 出處:http://ylbtech.cnblogs.com/ 本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。 |