在解析数据后插入存储过程中

时间:2014-11-12 09:04:58

标签: sql-server stored-procedures

我想请求有关如何直接插入使用select解析的解析数据的帮助。

这是我的代码人

已存储的程序

USE [SMSGPS]
GO
/****** Object:  StoredProcedure [dbo].[ParsingProcedureR10V2]    Script Date: 11/12/2014 1:08:10 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ParsingProcedureR10V2]
@ProductCode VARCHAR(500)
AS
SET NOCOUNT ON;
SELECT [Account]  = LEFT(@ProductCode,CHARINDEX(',',@ProductCode) - 1),
   [date&time] = SUBSTRING(@ProductCode, 27, 12),
   [Status] = SUBSTRING(@ProductCode, 40, 1),
   [Lat] = SUBSTRING(@ProductCode, 42, 10),
   [Long] = SUBSTRING(@ProductCode, 53, 11),
   [Speed] = SUBSTRING(@ProductCode, 65, 4),
       [HDOP] = SUBSTRING(@ProductCode, 74, 3),
   [statcode] = SUBSTRING(@ProductCode, 78, 8),
   [ENGINE] = SUBSTRING(@ProductCode, 78, 1),
   [KM2] = SUBSTRING(@ProductCode, 123,11);

感谢所有提前帮助我的人,感谢网站让我发帖。

1 个答案:

答案 0 :(得分:1)

尝试此操作:将TABLENAME替换为您的表名并运行它。

USE [SMSGPS]
GO
/****** Object:  StoredProcedure [dbo].[ParsingProcedureR10V2]    Script Date: 11/12/2014 1:08:10 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ParsingProcedureR10V2]
@ProductCode VARCHAR(500)
AS
SET NOCOUNT ON; 

INSERT INTO TABLENAME (Account, date&time, Status, Lat, Long, Speed, HDOP,  
      statcode, ENGINE, KM2) 
SELECT [Account]  = LEFT(@ProductCode,CHARINDEX(',',@ProductCode) - 1),
   [date&time] = SUBSTRING(@ProductCode, 27, 12),
   [Status] = SUBSTRING(@ProductCode, 40, 1),
   [Lat] = SUBSTRING(@ProductCode, 42, 10),
   [Long] = SUBSTRING(@ProductCode, 53, 11),
   [Speed] = SUBSTRING(@ProductCode, 65, 4),
   [HDOP] = SUBSTRING(@ProductCode, 74, 3),
   [statcode] = SUBSTRING(@ProductCode, 78, 8),
   [ENGINE] = SUBSTRING(@ProductCode, 78, 1),
   [KM2] = SUBSTRING(@ProductCode, 123,11);