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)
 Multiple CTE's problem

Author  Topic 

lotek
Starting Member

42 Posts

Posted - 2007-07-05 : 20:35:35
When I have multiple CTE's next to each other in my script then I get a funky error: Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ';'. But, if i take the semicolons out it doesnt work either. Anyone else had this problem?

;with table1 as
(
SELECT * FROM table
)

;with table2 as
(
SELECT * FROM table
)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-05 : 21:11:05
;with table1 as
(
SELECT * FROM table
)

,with table2 as
(
SELECT * FROM table
)

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

lotek
Starting Member

42 Posts

Posted - 2007-07-06 : 10:50:04
The problem persists even with the comma.

Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'with'.
Msg 319, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2007-07-06 : 10:57:31
Are you trying to have a common table expression with two common table definitions?
Go to Top of Page

lotek
Starting Member

42 Posts

Posted - 2007-07-06 : 11:28:29
Got it!

;with table1 as
(
SELECT * FROM table
)

,table2 as
(
SELECT * FROM table
)
Go to Top of Page
   

- Advertisement -