Tuesday, March 20, 2012

; in T-SQL

Hi there!
Are there any guidelines when a ";" must be used in T-SQL?
Thanks
Klaus Aschenbrenner
www.csharp.at,www.anecon.com
http://weblogs.asp.net/klaus.aschenbrenner";" ist optional as a statement separator. If you use just one
statement, then there is no need to separate or finalize the statement
with ";" like in oracle.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--|||Well, I suppose that if you come from languages such as C you will find more
confortable follow using them in Transact.
--
current location: alicante (es)
"Klaus Aschenbrenner" wrote:

> Hi there!
> Are there any guidelines when a ";" must be used in T-SQL?
> Thanks
> Klaus Aschenbrenner
> www.csharp.at,www.anecon.com
> http://weblogs.asp.net/klaus.aschenbrenner
>
>|||Jens wrote:
> ";" ist optional as a statement separator. If you use just one
> statement, then there is no need to separate or finalize the statement
> with ";" like in oracle.
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
However, in SQL Server 2005 the ; isn't always optional. So it may be a
good idea to get in the habit of using ; at the end of each statement
or at least between each pair of statements.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Klaus Aschenbrenner (Klaus.Aschenbrenner@.anecon.com) writes:
> Are there any guidelines when a ";" must be used in T-SQL?
In SQL 2005 you must have a ; before WITH when it comes first in a
statement, either you have WITH CTE (...) or WITH XML_NAMESPACES. There
are a few more statements new to SQL 2005 where you also need ;, I believe
that RECEIVE is one of them.
Generally, it's certainly a good idea to start use ; in your T-SQL code,
but I will have to admit that I don't do that myself.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||> However, in SQL Server 2005 the ; isn't always optional. So it may be a
> good idea to get in the habit of using ; at the end of each statement
> or at least between each pair of statements.
I have definitely gotten into that habit since early in the beta cycle...|||It has been optional in T-SQL, but has always been part of Standard
SQL. Those of us who have always Standard SQL once more do not have to
clean up our old code :)

No comments:

Post a Comment