Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Anybody using semicolon?

Author  Topic 

Sitka
Aged Yak Warrior

571 Posts

Posted - 2008-08-21 : 09:01:03
FROM BOL 2005

[;]
Optional Transact-SQL statement terminator. Do not type the brackets.


"it's definitely useless and maybe harmful".

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-21 : 09:03:29
quote:
Originally posted by Sitka

FROM BOL 2005

[;]
Optional Transact-SQL statement terminator. Do not type the brackets.


"it's definitely useless and maybe harmful".


Are you just giving the information or do you have any question?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-21 : 10:25:02
Yes. It's mandatory when using cte, unless cte is first statement of batch.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2008-08-21 : 11:13:49
FAILS

SELECT 'thanks'

WITH
JOHN(prfid,prfdate) AS
(
SELECT prfid, prfdate FROM prfs
),
JILL(prfid,department) AS
(
SELECT prfid, department FROM prfs
)

SELECT A.prfdate, B.department FROM JOHN A
INNER JOIN JILL B
ON A.prfid = B.prfid


RUNS


SELECT 'thanks';

WITH
JOHN(prfid,prfdate) AS
(
SELECT prfid, prfdate FROM prfs
),
JILL(prfid,department) AS
(
SELECT prfid, department FROM prfs
)

SELECT A.prfdate, B.department FROM JOHN A
INNER JOIN JILL B
ON A.prfid = B.prfid


Arron Bertrand said 05-Sep-07
quote:

You should get in the habit now of terminating all applicable statements
with semi-colons. This is becoming required as existing keywords are
re-purposed for new functionality, for example a semi-colon must append the
statement preceding any CTE definition (which starts with WITH) so that the
parser knows that WITH does not belong to the previous statement.



Second question..Where else is the use mandatory?

General interest...Stylistically what are folks doing?

No SQL2005 (or 2008) in production here.


Thanks

"it's definitely useless and maybe harmful".
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-21 : 11:40:11
i'm trying to start using them but i'm not getting anywhere
it's hard to switch when you don't have to.


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

jholovacs
Posting Yak Master

163 Posts

Posted - 2008-08-21 : 12:12:24
I use a bunch of different languages in my shop; I've pretty much gotten used to terminating every statement with a semicolon. I think it makes for cleaner code and is easier to debug when you know where your statements are meant to terminate.

___________________________
Geek At Large
Go to Top of Page
   

- Advertisement -