请高手看看?为何{"第 15 行: ',' 附近有语法错误。\r\n在关键字 'AS' 附近有语法错误。\r\n在关键字 'AS' 附近有语法错误。" }
IF charindex( '_ ',@FeederDep)> 0 AND charindex( '_ ',@Destination)> 0
BEGIN
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, '+
@FeederRoutingID + ', ' +
@OnlineRoutingID+ ', ' +
@InterlineRoutingID+ ', ' +
@FeederFareID+ ', ' +
@OnlineFareID+ ', ' +
@InterlineFareID+ ', ' +
@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
ORDER BY Departure,Destination ')
END
-- 2,@FeederDep为airport,@Destination为zone
IF charindex( '_ ',@FeederDep)=0 AND charindex( '_ ',@Destination)> 0
BEGIN
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, ' +
@FeederRoutingID+ ', ' +
@OnlineRoutingID+ ', ' +
@InterlineRoutingID+ ', ' +
@FeederFareID+ ', ' +
@OnlineFareID+ ', ' +
@InterlineFareID+ ', ' +
@ContractID+ ', ' +
@DateFrom+ ', ' +
@DateTo+ ', ' +
@IsRoundTrip+ ', ' +
@Airline + '
FROM
(
SELECT * FROM dbo.fn_split( ' + @FeederDep + ', ' + ', ' + ')
) 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
ORDER BY Departure,Destination ')
END
为何会报如此的错误
{ "第 15 行: ', ' 附近有语法错误。\r\n在关键字 'AS ' 附近有语法错误。\r\n在关键字 'AS ' 附近有语法错误。 " }
[解决办法]
太多。不忍看`
不过有个地方不是很理解。。
'INSERT ' + @Airline
@Airline应该是表名吧?那也应该是 'insert into '+@Airline噢``
就提个小小的疑问。
[解决办法]
類似動態語句的debug,一般都是先print出來,
然後debug,這樣基本可以搞定了
[解决办法]
here:
--SELECT * FROM dbo.fn_split( ' + @FeederDep + ', ' + ', ' + ')
SELECT * FROM dbo.fn_split( ' + @FeederDep + ',default ' + ',default ' + ')
[解决办法]
你这儿的函数是拆分,但参数写得可能有问题
SELECT * FROM dbo.fn_split( ' + @FeederDep + ', ' + ', ' + ')
[解决办法]
here:函数默认值要用default
--SELECT * FROM dbo.fn_split( ' + @FeederDep + ', ' + ', ' + ')
SELECT * FROM dbo.fn_split( ' ' ' + @FeederDep + ' ' ',default ' + ',default ' + ')