Prev: Strip the first byte from an image column.
Next: Question about stored procedures - please advise.
From: RG on 8 Jun 2010 09:13 I have seen in a couple of places that the use of begin and end block in a single statement is discouraged Outside of extra 2 lines of code, is there an issue in enclosing a single statement with begin and end block? Thanks in advance
From: Erland Sommarskog on 8 Jun 2010 10:14 RG (nobody(a)nowhere.com) writes: > I have seen in a couple of places that the use of begin and end block in a > single statement is discouraged > Outside of extra 2 lines of code, is there an issue in enclosing a single > statement with begin and end block? No. My personal style is that if the statement is a single line, I don't use BEGIN END: IF @dothis = 1 EXEC dothis @par1 But if the statement extends over several lines, I do use BEGIN END: IF @update = 1 BEGIN UPDATE tbl SET somecol = 11 WHERE col = @keyval END A good argument for always using BEGIN END is that avoids silly errors when changing code. Assume in the example above that a second procedure needs to be called: IF @dothis = 1 EXEC dothis @par1 EXEC dothat @par2 -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: --CELKO-- on 8 Jun 2010 11:02 >> I have seen in a couple of places that the use of begin and end block in a single statement is discouraged. Outside of extra 2 lines of code, is there an issue in enclosing a single statement with begin and end block? << It will not make any performance difference. The use of the redundant blocking go back to Algol and PL/I on punch cards. It was easier to add or remove cards when doing maintenance or debugging. Today, you hit the "magic button" in a text editor and pretty print your program after you make changes. Also modern programming languages have closing keywords, such as SQL/ PSM with the ADA style "IF.. THEN.. ELSE.. END IF;" constructs. I don't like using them myself. I think it misleads the eye, since a BEGIN tells me to look for multiple statements, and makes me want to see a comment to explain what the block does.
From: Jellifish on 8 Jun 2010 14:22 PUNCHED CARD ALERT!!!! PUNCHED CARD ALERT!!!! PUNCHED CARD ALERT!!!! "--CELKO--" <jcelko212(a)earthlink.net> wrote in message news:46e100fb-636c-4fb2-b8ef-2f138ec01e82(a)i28g2000yqa.googlegroups.com... >>> I have seen in a couple of places that the use of begin and end block in >>> a single statement is discouraged. Outside of extra 2 lines of code, is >>> there an issue in enclosing a single statement with begin and end block? >>> << > > It will not make any performance difference. The use of the redundant > blocking go back to Algol and PL/I on punch cards. It was easier to > add or remove cards when doing maintenance or debugging. > > Today, you hit the "magic button" in a text editor and pretty print > your program after you make changes. > > Also modern programming languages have closing keywords, such as SQL/ > PSM with the ADA style "IF.. THEN.. ELSE.. END IF;" constructs. > > I don't like using them myself. I think it misleads the eye, since a > BEGIN tells me to look for multiple statements, and makes me want to > see a comment to explain what the block does.
|
Pages: 1 Prev: Strip the first byte from an image column. Next: Question about stored procedures - please advise. |