如何在查询链接服务器中输入ip

时间:2016-08-22 07:10:50

标签: sql-server sql-server-2008 sql-server-2008-r2

我有查询如何在我的查询中输入服务器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, enter image description here

2 个答案:

答案 0 :(得分:4)

远程存储过程可以称为四部分名称:

EXEC [RemoteServer] .DatabaseName.DatabaseOwner.StoredProcedureName

我不确定您为什么使用动态SQL。试试这样。

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()

答案 1 :(得分: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