在链接服务器

时间:2017-12-06 15:28:14

标签: sql-server tsql

我有这个

IF @publishdr = 1 
BEGIN
TRUNCATE TABLE [LINKEDSERVERNAME].[Website-LIVE].[dbo].[VehicleData]
INSERT INTO [LINKEDSERVERNAME].[Website-LIVE].[dbo].[VehicleData]
(VehicleRef, Type, CapId, Maintenance, 
CH_2YR_SOURCE, CH_3YR_SOURCE, CH_4YR_SOURCE, PCH_2YR_SOURCE, PCH_3YR_SOURCE, PCH_4YR_SOURCE,
Manufacturer, Model, ShortModText, Derivative, ShortDerText, ManufacturerUrl, ModelUrl, ShortModTextUrl, DerivativeUrl, ShortDerTextUrl, VehicleUrl,
Category, LoCatCode, Fuel, Transmission, Doors, DriveTrain, Seats, Mpg, BodyType, BodyTypeId, 
CO2, EngineSize, InsuranceGroup, BHP, ManufacturerRRP,
VanCategory, VanMaxPayload, VanMaxLoadLength, VanMaxLoadWidthBetweenArches, VanMaxLoadWidth, VanMaxLoadHeight,
Co2TaxMonthly, Co2Tax40Monthly, IsInStock, AdhocVehicleRef,
InfoJson)
SELECT VehicleRef, Type, CapId, Maintenance, 
CH_2YR_SOURCE, CH_3YR_SOURCE, CH_4YR_SOURCE, PCH_2YR_SOURCE, PCH_3YR_SOURCE, PCH_4YR_SOURCE,
Manufacturer, Model, ShortModText, Derivative, ShortDerText, ManufacturerUrl, ModelUrl, ShortModTextUrl, DerivativeUrl, ShortDerTextUrl, VehicleUrl,
Category, LoCatCode, Fuel, Transmission, Doors, DriveTrain, Seats, Mpg, BodyType, BodyTypeId, 
CO2, EngineSize, InsuranceGroup, BHP, ManufacturerRRP,
VanCategory, VanMaxPayload, VanMaxLoadLength, VanMaxLoadWidthBetweenArches, VanMaxLoadWidth, VanMaxLoadHeight,
Co2TaxMonthly, Co2Tax40Monthly, IsInStock, AdhocVehicleRef,
InfoJson
FROM #VehicleData
END

我收到此错误:

对象名称' LINKEDSERVERNAME.Website-LIVE.dbo.VehicleData'包含超过最大前缀数。最大值为2。

我认为这是在链接服务器上指定表的正确语法。

由于

1 个答案:

答案 0 :(得分:2)

错误可能是由于您在链接服务器上尝试TRUNCATE TABLE这一事实,这是不受支持的。

请改为尝试:

EXEC [LINKEDSERVERNAME].[Website-LIVE].[sys].[sp_executesql] N'TRUNCATE TABLE dbo.VehicleData';