日期:2014-05-18  浏览次数:20450 次

服务器: 消息 170,级别 15,状态 1,行 14
SELECT c.ThreeCantonNumber as areano,c.ThreeCantonName,(a.FirstCantonName+b.SecondCantonName+c.ThreeCantonName) as AreaName from(
SELECT a.FirstCantonNumber, 
  b.SecondCantonNumber, 
  c.ThreeCantonNumber, a.FirstCantonName, 
  b.SecondCantonName, 
  c.ThreeCantonName
FROM dbo.T_FirstCanton a LEFT OUTER JOIN
  dbo.T_SecondCanton b ON 
  a.FirstCantonNumber = b.FirstCantonNumber LEFT
  OUTER JOIN
  dbo.T_ThreeCanton c ON 
  b.SecondCantonNumber = c.SecondCantonNumber
)
服务器: 消息 170,级别 15,状态 1,行 14
第 14 行: ')' 附近有语法错误。


------解决方案--------------------
SQL code
SELECT c.ThreeCantonNumber as areano,c.ThreeCantonName,(a.FirstCantonName+b.SecondCantonName+c.ThreeCantonName) as AreaName from(
SELECT a.FirstCantonNumber,  
  b.SecondCantonNumber,  
  c.ThreeCantonNumber, a.FirstCantonName,  
  b.SecondCantonName,  
  c.ThreeCantonName
FROM dbo.T_FirstCanton a LEFT OUTER JOIN
  dbo.T_SecondCanton b ON  
  a.FirstCantonNumber = b.FirstCantonNumber LEFT
  OUTER JOIN
  dbo.T_ThreeCanton c ON  
  b.SecondCantonNumber = c.SecondCantonNumber
) t--加个别名

------解决方案--------------------
SQL code

SELECT c.ThreeCantonNumber as areano,c.ThreeCantonName,(a.FirstCantonName+b.SecondCantonName+c.ThreeCantonName) as AreaName from(
SELECT a.FirstCantonNumber,  
  b.SecondCantonNumber,  
  c.ThreeCantonNumber, a.FirstCantonName,  
  b.SecondCantonName,  
  c.ThreeCantonName
FROM dbo.T_FirstCanton a LEFT OUTER JOIN
  dbo.T_SecondCanton b ON  
  a.FirstCantonNumber = b.FirstCantonNumber LEFT
  OUTER JOIN
  dbo.T_ThreeCanton c ON  
  b.SecondCantonNumber = c.SecondCantonNumber
) as a --别名

------解决方案--------------------
SQL code
SELECT ThreeCantonNumber as areano,ThreeCantonName,(FirstCantonName+SecondCantonName+ThreeCantonName) as AreaName from
(
SELECT a.FirstCantonNumber,  
  b.SecondCantonNumber,  
  c.ThreeCantonNumber, a.FirstCantonName,  
  b.SecondCantonName,  
  c.ThreeCantonName
FROM dbo.T_FirstCanton a LEFT OUTER JOIN
  dbo.T_SecondCanton b ON  
  a.FirstCantonNumber = b.FirstCantonNumber LEFT
  OUTER JOIN
  dbo.T_ThreeCanton c ON  
  b.SecondCantonNumber = c.SecondCantonNumber
) AS T

------解决方案--------------------
SQL code
SELECT c.ThreeCantonNumber as areano,c.ThreeCantonName,(a.FirstCantonName+b.SecondCantonName+c.ThreeCantonName) as AreaName from(
SELECT a.FirstCantonNumber,  
  b.SecondCantonNumber,  
  c.ThreeCantonNumber, a.FirstCantonName,  
  b.SecondCantonName,  
  c.ThreeCantonName
FROM dbo.T_FirstCanton a LEFT OUTER JOIN
  dbo.T_SecondCanton b ON  
  a.FirstCantonNumber = b.FirstCantonNumber LEFT
  OUTER JOIN
  dbo.T_ThreeCanton c ON  
  b.SecondCantonNumber = c.SecondCantonNumber
)tt

------解决方案--------------------
直接

SQL code
SELECT c.ThreeCantonNumber as areano,c.ThreeCantonName,(a.FirstCantonName+b.SecondCantonName+c.ThreeCantonName) as AreaName 
FROM dbo.T_FirstCanton a LEFT OUTER JOIN
  dbo.T_SecondCanton b ON  
  a.FirstCantonNumber = b.FirstCantonNumber LEFT
  OUTER JOIN
  dbo.T_ThreeCanton c ON  
  b.SecondCantonNumber = c.SecondCantonNumber

------解决方案--------------------
子查询必须别名

SQL code
SELECT ThreeCantonNumber as areano,ThreeCantonName,(FirstCantonNameA+SecondCantonNameB+ThreeCantonNameC) as AreaName from
(
SELECT a.FirstCantonNumber,  
  b.SecondCantonNumber,  
  c.ThreeCantonNumber, a.FirstCantonName AS FirstCantonNameA , 
  b.SecondCantonName AS FirstCantonNameB  ,  
  c.ThreeCantonName AS FirstCant