存储过程代码:
--订单信息添加存储过程
ALTER PROCEDURE P_BatchImportOrders
@OutCustomerName nvarchar(20),
@OutCustomerID int,
@OutCompanyIp nvarchar(300),
@OutPackageID int,
@OutproductID int,
@OutGeneratorRoom nvarchar(50),
@OutServerTypeID int,
@OutCpu nvarchar(50),
@OutBandwidth nvarchar(50),
@OutHardDisk nvarchar(50),
@OutMemory nvarchar(50),
@Outprice float,
@OutStaffID int,
@OutTechnology nvarchar(10),
@OutOrderDate datetime,
@OutExpirationDate datetime,
@OutModificationCost float,
@OutRenewalDate datetime,
@OutRenewalStatus int,
@OutRenewalFee float,
@OutRemarks nvarchar(MAX),
@OutEntryPerson nvarchar(20),
@OutOrderID int
as
begin
declare @CustomerID nvarchar(20)
select @CustomerID=CustomerID from Customer where CustomerName=@OutCustomerName
set @OutCustomerID=@CustomerID
begin
if @OutPackageID<=0
begin
insert into Products values(@Outprice,@OutGeneratorRoom,@OutServerTypeID,@OutCpu,@OutBandwidth,@OutHardDisk,@OutMemory)
declare @productID int
select @productID=max(productID) from Products
set @OutproductID=@productID
end
else
begin
set @OutproductID=0
end
insert into TableOrders(CustomerID,PackageID,productID,StaffID,Technology,OrderDate,ExpirationDate,ModificationCost,RenewalDate,RenewalStatus,RenewalFee,Remarks,EntryPerson,state) values (@OutCustomerID,@OutPackageID,@OutproductID,@OutStaffID,@OutTechnology,@OutOrderDate,@OutExpirationDate,@OutModificationCost,@OutRenewalDate,@OutRenewalStatus,@OutRenewalFee,@OutRemarks,@OutEntryPerson,0)
declare @orderid int
select @orderid=max(OrderID) from TableOrders
set @OutOrderID=@orderid
begin
insert into UseCompanyIp(IpAddress,OrderIDs) values (@OutCompanyIp,@OutOrderID)
insert into CompanyIp(IpAddress,IpState,OrderID) values (@OutCompanyIp,1,@OutOrderID)
end
end
end
主要是这里插入语句的时候:
insert into UseCompanyIp(IpAddress,OrderIDs) values (@OutCompanyIp,@OutOrderID)
insert into CompanyIp(IpAddress,IpState,OrderID) values(@OutCompanyIp,1,@OutOrderID)
比如一个IP是这样的:192.168.1.1|192.168.2.2|192.168.3.3 订单编号是:201301
第一条插入语句IP地址可以直接当字符串插入,第二条必须得分开这样分开单个IP插入对应一个订单号比如这样:192.168.1.1 -201301,192.168.2.2-201301,192.168.3.3-201301,意思就是拆分插入,请问一下在存储过程里面怎么完成,怎么做呀??、
SQL,存储过程
------解决方案--------------------
改成这样试试:
--订单信息添加存储过程
ALTER PROCEDURE P_BatchImportOrders
@OutCustomerName nvarchar(20),
@OutCustomerID int,
@OutCompanyIp nvarchar(300),
@OutPackageID int,
@OutproductID int,
@OutGeneratorRoom nvarchar(50),
@OutServerTypeID int,
@OutCpu nvarchar(50),
@OutBandwidth nvarchar(50),
@OutHardDisk nvarchar(50),
@OutMemory nvarchar(50),
@Outprice float,
@OutStaffID int,
@OutTechnology nvarchar(10),
@OutOrderDate datetime,
@OutExpirationDate datetime,
@OutModificationCost float,
@OutRenewalDate datetime,
@OutRenewalStatus int,
@OutRenewalFee float,
@OutRemarks nvarchar(MAX),
@OutEntryPerson nvarchar(20),
@OutOrderID int
as
begin
declare @CustomerID nvarchar(20)
select @CustomerID=CustomerID from Customer where CustomerName=@OutCustomerName
set @OutCustomerID=@CustomerID
begin
if @OutPackageID<=0
begin
insert into Products values(@Outprice,@OutGeneratorRoom,@OutServerTypeID,@OutCpu,@OutBandwidth,@OutHardDisk,@OutMemory)
declare @productID int
select @productID=max(productID) from Products
set @OutproductID=@productID
end
else
begin
set @OutproductID=0
end
insert into TableOrders(CustomerID,PackageID,productID,StaffID,Technology,OrderDate,ExpirationDate,ModificationCost,RenewalDate,RenewalStatus,RenewalFee,Remarks,EntryPerson,state) values (@OutCustomerID,@OutPackageID,@OutproductID,@OutStaffID,@OutTechnology,@OutOrderDate,@OutExpirationDate,@OutModificationCost,@OutRenewalDate,@OutRenewalStatus,@OutRenewalFee,@OutRemarks,@OutEntryPerson,0)
declare @orderid int
select @orderid=max(OrderID) from TableOrders
set @OutOrderID=@orderid
begin
insert into UseCompanyIp(IpAddress,OrderIDs)
values (@OutCompanyIp,@OutOrderID)
insert into CompanyIp(IpAddress,IpState,OrderID)
select SUBSTRING(t.OutCompanyIp, number ,
CHARINDEX('
------解决方案--------------------