how to use with and inner join in Sql server query?

时间:2015-10-06 09:00:41

标签: inner-join

Why this query must be incorrect ? :

with a as 
(
  select * 
  from justification_game_publisher 
  inner join justifications 
  on justifications.id = justification_id 
  where game_id=1594
) 
select * 
from games_publisher_class 
inner join a  
on a.game_id = games_publisher_class.game_id 
and a.publisher_id = games_publisher_class.publisher_id

sql server says :

Msg 319, Level 15, State 1, Line 2: 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.

1 个答案:

答案 0 :(得分:0)

我认为你之前有额外的sql表达式。 尝试

;with a as (....

而不是

with a as (....

我希望这应该有所帮助:)