2016-08-22 152 views
0

我已經follwing查詢如何在我的查詢中輸入服務器的IP,請幫我輸入IP,如何在查詢鏈接服務器

DECLARE @ScopeIdentity int; 

    EXEC 175.120.124.162.Taxi.sp_executesql N'INSERT INTO [175.110.104.162].Taxi.dbo.booking (FromLocTypeId,ToLocTypeId,FromLocId,ToLocId,VehicleTypeId,DriverId,ReturnDriverId,CustomerId,CustomerName,CustomerEmail,CustomerPhoneNo,CustomerMobileNo,JourneyTypeId,BookingNo,BookingDate,NoofPassengers,NoofLuggages,NoofHandLuggages,PickupDateTime,ReturnPickupDateTime,IsCompanyWise,CompanyId,FareRate,PaymentTypeId,SpecialRequirements,FromAddress,ToAddress,FromPostCode,ToPostCode,FromDoorNo,ToDoorNo,FromStreet,ToStreet,FromFlightNo,FromComing,BookingStatusId,DistanceString,AutoDespatch,AutoDespatchTime,AddOn,AddBy,AddLog,EditOn,EditBy,EditLog,OrderNo,PupilNo,ParkingCharges,WaitingCharges,ExtraDropCharges,MeetAndGreetCharges,CongtionCharges,TotalCharges,DepartmentId,ReturnFareRate 
    ,ArrivalDateTime,MasterJobId,DisablePassengerSMS,DisableDriverSMS,IsCommissionWise,DriverCommission,DespatchDateTime,JobOfferDateTime,BookingTypeId,DriverCommissionType,IsBidding,IsQuotation,CostCenterId,CashRate,AccountRate,WaitingMins 
    ,ExtraMile,AcceptedDateTime,POBDateTime,STCDateTime,ClearedDateTime,CancelReason,TotalTravelledMiles,CompanyPrice,SubCompanyId,PartyId, 
    FromOther,ToOther,TransferJobId,TransferJobCommission,BookingTypeId,ViaString) 

    SELECT 
    FromLocTypeId,ToLocTypeId,FromLocId,ToLocId,VehicleTypeId,null,ReturnDriverId,CustomerId,CustomerName,CustomerEmail,CustomerPhoneNo,CustomerMobileNo,JourneyTypeId,BookingNo,BookingDate,NoofPassengers,NoofLuggages,NoofHandLuggages,PickupDateTime,ReturnPickupDateTime,IsCompanyWise,null,FareRate,PaymentTypeId,SpecialRequirements,FromAddress,ToAddress,FromPostCode,ToPostCode,FromDoorNo,ToDoorNo,FromStreet,ToStreet,FromFlightNo,FromComing,BookingStatusId,DistanceString,AutoDespatch,AutoDespatchTime,AddOn,AddBy,AddLog,EditOn,EditBy,EditLog,OrderNo,PupilNo,ParkingCharges,WaitingCharges,ExtraDropCharges,MeetAndGreetCharges,CongtionCharges,TotalCharges,DepartmentId,ReturnFareRate 
    ,ArrivalDateTime,MasterJobId,DisablePassengerSMS,DisableDriverSMS,IsCommissionWise,DriverCommission,DespatchDateTime,JobOfferDateTime,BookingTypeId,DriverCommissionType,IsBidding,IsQuotation,CostCenterId,CashRate,AccountRate,WaitingMins 
    ,ExtraMile,AcceptedDateTime,POBDateTime,STCDateTime,ClearedDateTime,CancelReason,TotalTravelledMiles,CompanyPrice,1,@PartyId 
    ,FromOther,ToOther,@JOB_id,@Commission,10,ViaString 

    FROM Booking 
    WHERE Id = @JOB_id ;select SCOPE_IDENTITY()'; 
    SELECT @ScopeIdentity; 

IP地址告訴我錯誤怎麼進入鏈接服務器的名字,我想Scopeidentity爲什麼使用動態SQL您

EXEC [RemoteServer] .DatabaseName.DatabaseOwner.StoredProcedureName 

我不知道:, enter image description here

回答

2

遠程存儲過程可以被稱爲四個部分名稱。像這樣嘗試。

DECLARE @ScopeIdentity INT; 

INSERT INTO [175.110.104.162].Taxi.dbo.booking (
    FromLocTypeId 
    ,ToLocTypeId 
    ,FromLocId 
    ,ToLocId 
    ,VehicleTypeId 
    ,DriverId 
    ,ReturnDriverId 
    ,CustomerId 
    ,CustomerName 
    ,CustomerEmail 
    ,CustomerPhoneNo 
    ,CustomerMobileNo 
    ,JourneyTypeId 
    ,BookingNo 
    ,BookingDate 
    ,NoofPassengers 
    ,NoofLuggages 
    ,NoofHandLuggages 
    ,PickupDateTime 
    ,ReturnPickupDateTime 
    ,IsCompanyWise 
    ,CompanyId 
    ,FareRate 
    ,PaymentTypeId 
    ,SpecialRequirements 
    ,FromAddress 
    ,ToAddress 
    ,FromPostCode 
    ,ToPostCode 
    ,FromDoorNo 
    ,ToDoorNo 
    ,FromStreet 
    ,ToStreet 
    ,FromFlightNo 
    ,FromComing 
    ,BookingStatusId 
    ,DistanceString 
    ,AutoDespatch 
    ,AutoDespatchTime 
    ,AddOn 
    ,AddBy 
    ,AddLog 
    ,EditOn 
    ,EditBy 
    ,EditLog 
    ,OrderNo 
    ,PupilNo 
    ,ParkingCharges 
    ,WaitingCharges 
    ,ExtraDropCharges 
    ,MeetAndGreetCharges 
    ,CongtionCharges 
    ,TotalCharges 
    ,DepartmentId 
    ,ReturnFareRate 
    ,ArrivalDateTime 
    ,MasterJobId 
    ,DisablePassengerSMS 
    ,DisableDriverSMS 
    ,IsCommissionWise 
    ,DriverCommission 
    ,DespatchDateTime 
    ,JobOfferDateTime 
    ,BookingTypeId 
    ,DriverCommissionType 
    ,IsBidding 
    ,IsQuotation 
    ,CostCenterId 
    ,CashRate 
    ,AccountRate 
    ,WaitingMins 
    ,ExtraMile 
    ,AcceptedDateTime 
    ,POBDateTime 
    ,STCDateTime 
    ,ClearedDateTime 
    ,CancelReason 
    ,TotalTravelledMiles 
    ,CompanyPrice 
    ,SubCompanyId 
    ,PartyId 
    ,FromOther 
    ,ToOther 
    ,TransferJobId 
    ,TransferJobCommission 
    ,BookingTypeId 
    ,ViaString 
    ) 
SELECT FromLocTypeId 
    ,ToLocTypeId 
    ,FromLocId 
    ,ToLocId 
    ,VehicleTypeId 
    ,NULL 
    ,ReturnDriverId 
    ,CustomerId 
    ,CustomerName 
    ,CustomerEmail 
    ,CustomerPhoneNo 
    ,CustomerMobileNo 
    ,JourneyTypeId 
    ,BookingNo 
    ,BookingDate 
    ,NoofPassengers 
    ,NoofLuggages 
    ,NoofHandLuggages 
    ,PickupDateTime 
    ,ReturnPickupDateTime 
    ,IsCompanyWise 
    ,NULL 
    ,FareRate 
    ,PaymentTypeId 
    ,SpecialRequirements 
    ,FromAddress 
    ,ToAddress 
    ,FromPostCode 
    ,ToPostCode 
    ,FromDoorNo 
    ,ToDoorNo 
    ,FromStreet 
    ,ToStreet 
    ,FromFlightNo 
    ,FromComing 
    ,BookingStatusId 
    ,DistanceString 
    ,AutoDespatch 
    ,AutoDespatchTime 
    ,AddOn 
    ,AddBy 
    ,AddLog 
    ,EditOn 
    ,EditBy 
    ,EditLog 
    ,OrderNo 
    ,PupilNo 
    ,ParkingCharges 
    ,WaitingCharges 
    ,ExtraDropCharges 
    ,MeetAndGreetCharges 
    ,CongtionCharges 
    ,TotalCharges 
    ,DepartmentId 
    ,ReturnFareRate 
    ,ArrivalDateTime 
    ,MasterJobId 
    ,DisablePassengerSMS 
    ,DisableDriverSMS 
    ,IsCommissionWise 
    ,DriverCommission 
    ,DespatchDateTime 
    ,JobOfferDateTime 
    ,BookingTypeId 
    ,DriverCommissionType 
    ,IsBidding 
    ,IsQuotation 
    ,CostCenterId 
    ,CashRate 
    ,AccountRate 
    ,WaitingMins 
    ,ExtraMile 
    ,AcceptedDateTime 
    ,POBDateTime 
    ,STCDateTime 
    ,ClearedDateTime 
    ,CancelReason 
    ,TotalTravelledMiles 
    ,CompanyPrice 
    ,1 
    ,@PartyId 
    ,FromOther 
    ,ToOther 
    ,@JOB_id 
    ,@Commission 
    ,10 
    ,ViaString 
FROM Booking 
WHERE Id = @JOB_id; 

SELECT SCOPE_IDENTITY() 
+0

您可能還需要考慮到,無論是命名實例/默認實例.. – TheGameiswar

+0

我是直接撥號的預訂表名 –

+0

SCOPE_IDENTITY返回NULL, –

1

試試這個

DECLARE @ScopeIdentity int; 
declare @identity table (ids int) 
insert into @identity 
    EXEC ('INSERT INTO [175.110.104.162].Taxi.dbo.booking (FromLocTypeId,ToLocTypeId,FromLocId,ToLocId,VehicleTypeId,DriverId,ReturnDriverId,CustomerId,CustomerName,CustomerEmail,CustomerPhoneNo,CustomerMobileNo,JourneyTypeId,BookingNo,BookingDate,NoofPassengers,NoofLuggages,NoofHandLuggages,PickupDateTime,ReturnPickupDateTime,IsCompanyWise,CompanyId,FareRate,PaymentTypeId,SpecialRequirements,FromAddress,ToAddress,FromPostCode,ToPostCode,FromDoorNo,ToDoorNo,FromStreet,ToStreet,FromFlightNo,FromComing,BookingStatusId,DistanceString,AutoDespatch,AutoDespatchTime,AddOn,AddBy,AddLog,EditOn,EditBy,EditLog,OrderNo,PupilNo,ParkingCharges,WaitingCharges,ExtraDropCharges,MeetAndGreetCharges,CongtionCharges,TotalCharges,DepartmentId,ReturnFareRate 
    ,ArrivalDateTime,MasterJobId,DisablePassengerSMS,DisableDriverSMS,IsCommissionWise,DriverCommission,DespatchDateTime,JobOfferDateTime,BookingTypeId,DriverCommissionType,IsBidding,IsQuotation,CostCenterId,CashRate,AccountRate,WaitingMins 
    ,ExtraMile,AcceptedDateTime,POBDateTime,STCDateTime,ClearedDateTime,CancelReason,TotalTravelledMiles,CompanyPrice,SubCompanyId,PartyId, 
    FromOther,ToOther,TransferJobId,TransferJobCommission,BookingTypeId,ViaString) 

    SELECT 
    FromLocTypeId,ToLocTypeId,FromLocId,ToLocId,VehicleTypeId,null,ReturnDriverId,CustomerId,CustomerName,CustomerEmail,CustomerPhoneNo,CustomerMobileNo,JourneyTypeId,BookingNo,BookingDate,NoofPassengers,NoofLuggages,NoofHandLuggages,PickupDateTime,ReturnPickupDateTime,IsCompanyWise,null,FareRate,PaymentTypeId,SpecialRequirements,FromAddress,ToAddress,FromPostCode,ToPostCode,FromDoorNo,ToDoorNo,FromStreet,ToStreet,FromFlightNo,FromComing,BookingStatusId,DistanceString,AutoDespatch,AutoDespatchTime,AddOn,AddBy,AddLog,EditOn,EditBy,EditLog,OrderNo,PupilNo,ParkingCharges,WaitingCharges,ExtraDropCharges,MeetAndGreetCharges,CongtionCharges,TotalCharges,DepartmentId,ReturnFareRate 
    ,ArrivalDateTime,MasterJobId,DisablePassengerSMS,DisableDriverSMS,IsCommissionWise,DriverCommission,DespatchDateTime,JobOfferDateTime,BookingTypeId,DriverCommissionType,IsBidding,IsQuotation,CostCenterId,CashRate,AccountRate,WaitingMins 
    ,ExtraMile,AcceptedDateTime,POBDateTime,STCDateTime,ClearedDateTime,CancelReason,TotalTravelledMiles,CompanyPrice,1,@PartyId 
    ,FromOther,ToOther,@JOB_id,@Commission,10,ViaString 

    FROM Booking 
    WHERE Id = @JOB_id ;select SCOPE_IDENTITY()') at 175.120.124.162 

set @ScopeIdentity=(select top 1 ids from @identity) 
select @ScopeIdentity 
相關問題