問題描述
我需要將我的 T-SQL 存儲過程 (MS SQL 2008) 控制流分支到多個方向:
I need to branch my T-SQL stored procedure (MS SQL 2008) control flow to a number of directions:
CREATE PROCEDURE [fooBar]
@inputParam INT
AS
BEGIN
IF @inputParam = 1
BEGIN
...
END
ELSE IF @inputParam = 3
BEGIN
...
END
ELSE IF @inputParam = 3
BEGIN
...
END
END
還有其他方法嗎?例如,在 C#
中,我應(yīng)該使用 switch-case
塊.
Is there any other ways? For example, in C#
I shoud use switch-case
block.
推薦答案
IF...ELSE... 幾乎就是我們在 T-SQL 中得到的.沒有什么比結(jié)構(gòu)化編程的 CASE 語句更像的了.如果您有一組擴(kuò)展的 ...ELSE IF... 需要處理,請確保為每個塊包含 BEGIN...END 以保持清晰,并始終記住,一致的縮進(jìn)是您的朋友!
IF...ELSE... is pretty much what we've got in T-SQL. There is nothing like structured programming's CASE statement. If you have an extended set of ...ELSE IF...s to deal with, be sure to include BEGIN...END for each block to keep things clear, and always remember, consistent indentation is your friend!
這篇關(guān)于使用 IF..ELSE IF 在 T-SQL SP 中控制流 - 還有其他方法嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!