Skip to main content

Parse text field in sql server

Parsing TEXT field with Long String

ALTER PROCEDURE [dbo].[DrawMap_KMLImport]
@ProcedureID int,
@ProjectID int,
@Shape varchar(30) = null,
@ObjName varchar(100) = null,
@Notes varchar(1000) = null,
@Allcoords text = null,
@Fillcolor int = null,
@ForeColor int = null

AS
declare @selectByte int
declare @coords varchar(7600)
declare @startI int
set @selectByte = 7600
if @ProcedureID =0
begin


if right(@coords,1) <> ' '
set @coords = @coords + ' '
declare @libID integer
declare @objID varchar(40)
if @shape = 'point'
set @libID = 58
else if @shape = 'polyline'
set @libID = 32
else
set @libID = 30
set @objID = NEWID()
insert into drawmap_objects (ObjID, objName, ProjectID, libID, visible, fillcolor, forecolor)
values(@objID, @objName, @projectID, @libID, 1, @fillcolor, @forecolor)

declare @latlong varchar(30)
declare @long varchar(30)
declare @lat varchar(30)
declare @index int
declare @pointID varchar(40)
declare @i int
set @i = 0
set @startI = 1
while @startI + @selectByte - 1 <= datalength(@Allcoords) begin set @coords = substring(@Allcoords, @startI, @selectByte) WHILE CHARINDEX(',0 ',@coords) > 0
BEGIN
set @i = @i + 1
set @index = CHARINDEX(',0 ',@coords)
SELECT @latlong = ltrim(rtrim(SUBSTRING(@coords,1,@index -1)))
select @long = substring(@latlong, 1, CHARINDEX(',',@latlong)-1)
select @lat = substring(@latlong, CHARINDEX(',',@latlong)+1, datalength(@latlong))

set @pointID = NEWID()
insert into drawmap_point(pointID, objID, pointindex, lat, long)
values(@pointID, @objID, @i,@lat, @long)

SELECT @coords = SUBSTRING(@coords,@index+3,DATALENGTH(@coords))
END
set @startI = @startI + @selectByte
end
set @coords = @coords + substring(@Allcoords, @startI, datalength(@Allcoords) - (@starti) + 1)

WHILE CHARINDEX(',0 ',@coords) > 0
BEGIN
set @i = @i + 1
set @index = CHARINDEX(',0 ',@coords)
SELECT @latlong = ltrim(rtrim(SUBSTRING(@coords,1,@index -1)))
select @long = substring(@latlong, 1, CHARINDEX(',',@latlong)-1)
select @lat = substring(@latlong, CHARINDEX(',',@latlong)+1, datalength(@latlong))

set @pointID = NEWID()
insert into drawmap_point(pointID, objID, pointindex, lat, long)
values(@pointID, @objID, @i,@lat, @long)

SELECT @coords = SUBSTRING(@coords,@index+3,DATALENGTH(@coords))
END

return
end

Comments

Popular posts from this blog

Web synchronization option for merge replication

http://msdn2.microsoft.com/en-us/library/ms151319.aspx SQL Server 2005 Books Online Implementing Replication over the Internet Replicating data over the Internet allows remote, disconnected users to access data when they need it using a connection to the Internet. Replicate data over the Internet using: A Virtual Private Network (VPN). For more information, see Publishing Data over the Internet Using VPN . The Web synchronization option for merge replication. For more information, see Web Synchronization for Merge Replication . All types of Microsoft SQL Server replication can replicate data over a VPN, but you should consider Web synchronization if you are using merge replication.

Request Signatures in Blackberry

Request Signatures in Blackberry need copy sigtool.db, sigtool.csk to SDK/component/Bin folder for example V 4.2.1 ../eclipse\plugins\net.rim.eide.componentpack4.2.1_4.2.1.17\components\bin