December 14, 2009 at 10:29 am
I'm trying to create a view for my large query which contains 3 common table expressions. Below is an excerpt of what I'm trying to accomplish
create view vDimBooks as (
with Publisher as (
...
),
Author as (
...
),
Editor as (
...)
select * from Publisher
INNER JOIN Author on Publisher.ID = Author.PublisherID
INNER JOIN Editor on Editor.ID = Author.EditorID
)
However, when I try to execute this statement to create the view, I get the following error:
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
I understand that I need to provide a semi-colon within that whole mix, but am not sure exactly where to place it. I've tried multiple places, but still get the same error. Any ideas?
December 14, 2009 at 10:31 am
before the with: ";with Publisher"
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
December 14, 2009 at 10:34 am
I have tried to put the semi-colon before the with Publishers, but I get an error which states "Incorrect Syntax near ';'
December 14, 2009 at 10:41 am
Loose the first per of parentheses that surround the whole view definition (the one that starts after vDimBooks and ends the view definition. If this won’t fix it, pleas show the full view definition.
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
December 14, 2009 at 10:44 am
That was the trick! Thanks Adi!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply