首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

服务器: 消息 170,级别 15,状态 1,行 117 行: 'CASE WHEN ' 附近有语法异常

2012-01-30 
服务器: 消息 170,级别 15,状态 1,行 117 行: CASE WHEN 附近有语法错误。EXEC(INSERT+@Airline+(Depart

服务器: 消息 170,级别 15,状态 1,行 117 行: 'CASE WHEN ' 附近有语法错误。
EXEC( '
INSERT   '   +     @Airline   + '   (
Departure,
Destination,
FeederRoutingID,
OnlineRoutingID,
InterlineRoutingID,
FeederFareID,
OnlineFareID,
InterlineFareID,
ContractID,
DateFrom,
DateTo,
IsRoundTrip,
Airline)
SELECT   t1.a   as   Departure,t2.a   as   Destination, '
'CASE   WHEN   '   +   @FeederRoutingID   +   '   IS   NULL   THEN   NULL   ELSE   '   ' '   +   @FeederRoutingID   +   ' ' '   END   , ' ' '   +  
@OnlineRoutingID+   ' ' ', '   +  
'CASE   WHEN   '   +   @InterlineRoutingID   +     'IS   NULL   THEN   NULL   ELSE   '   ' '   +   @InterlineRoutingID   +   ' ' '   END   , ' ' '   +  
'CASE   WHEN   '   +   @FeederFareID   +     'IS   NULL   THEN   NULL   ELSE   '   ' '   +   @FeederFareID   +   ' ' '   END   , ' ' '   +  
@OnlineFareID+   ' ' ', '   +  
'CASE   WHEN   '   +   @InterlineFareID   +     'IS   NULL   THEN   NULL   ELSE   '   ' '   +   @InterlineFareID   +   ' ' '   END   , ' ' '   +  
@ContractID+   ' ' ', ' ' '   +  
@DateFrom+   ' ' ', ' ' '   +  
@DateTo+   ' ' ', ' ' '   +  
@IsRoundTrip+   ' ' ', ' ' '   +  
@Airline   +   ' ' '   FROM
(
select   airportcode   As   a   from  
(
select   *   from   zone   where   zoneNo= ' ' '+   @FeederDep   +   ' ' ')Z
INNER   JOIN   ZoneElement   ZE   ON   Z.zoneID=ZE.zoneID
INNER   JOIN   MST_AirPort   A   ON   A.AirPortID=ZE.AirPortID  
)   AS   t1
CROSS   JOIN
(
select   airportcode   As   a   from  
(
select   *   from   zone   where   zoneNo= ' ' '+   @Destination   +   ' ' ')Z
INNER   JOIN   ZoneElement   ZE   ON   Z.zoneID=ZE.zoneID
INNER   JOIN   MST_AirPort   A   ON   A.AirPortID=ZE.AirPortID  
)   AS   t2
')

[解决办法]
SELECT t1.a as Departure,t2.a as Destination, '+ --很显然这里少了一个+号
[解决办法]
EXEC( '
INSERT ' + @Airline + ' (
Departure,
Destination,
FeederRoutingID,
OnlineRoutingID,
InterlineRoutingID,
FeederFareID,
OnlineFareID,
InterlineFareID,
ContractID,
DateFrom,
DateTo,
IsRoundTrip,
Airline)
SELECT t1.a as Departure,t2.a as Destination,CASE WHEN ' + -----这里有问题


@FeederRoutingID + ' IS NULL THEN NULL ELSE ' ' ' + @FeederRoutingID + ' ' ' END , ' ' ' +
@OnlineRoutingID+ ' ' ', ' +
'CASE WHEN ' + @InterlineRoutingID + 'IS NULL THEN NULL ELSE ' ' ' + @InterlineRoutingID + ' ' ' END , ' ' ' +
'CASE WHEN ' + @FeederFareID + 'IS NULL THEN NULL ELSE ' ' ' + @FeederFareID + ' ' ' END , ' ' ' +
@OnlineFareID+ ' ' ', ' +
'CASE WHEN ' + @InterlineFareID + 'IS NULL THEN NULL ELSE ' ' ' + @InterlineFareID + ' ' ' END , ' ' ' +
@ContractID+ ' ' ', ' ' ' +
@DateFrom+ ' ' ', ' ' ' +
@DateTo+ ' ' ', ' ' ' +
@IsRoundTrip+ ' ' ', ' ' ' +
@Airline + ' ' ' FROM
(
select airportcode As a from
(
select * from zone where zoneNo= ' ' '+ @FeederDep + ' ' ')Z
INNER JOIN ZoneElement ZE ON Z.zoneID=ZE.zoneID
INNER JOIN MST_AirPort A ON A.AirPortID=ZE.AirPortID
) AS t1
CROSS JOIN
(
select airportcode As a from
(
select * from zone where zoneNo= ' ' '+ @Destination + ' ' ')Z
INNER JOIN ZoneElement ZE ON Z.zoneID=ZE.zoneID
INNER JOIN MST_AirPort A ON A.AirPortID=ZE.AirPortID
) AS t2
')

热点排行