1
ALTER PROCEDURE dbo.StoredProcedure1    
AS  
DECLARE @Seedid int, @data1 float, @data2 float, @g geometry  

DECLARE member_cursor CURSOR FOR  
SELECT id from test1 ;  

OPEN member_cursor;  

FETCH NEXT FROM member_cursor  
INTO @Seedid ;  
WHILE @@FETCH_STATUS = 0  
BEGIN  
    select @data1 =data1 from test where id=@Seedid  
    select @data2 =data2 from test where id=@Seedid  
    update test1  
       set data4 = geometry::STGeomFromText('POINT (@data1 @data2)', 0)
        where id=@Seedid;  
    -- This is executed as long as the previous fetch succeeds.  
    FETCH NEXT FROM member_cursor  
    INTO @Seedid ;  
END  
RETURN  
CLOSE member_cursor;  
DEALLOCATE member_cursor;  

我收到以下错误:

该语句已终止。
在执行用户定义的例程或聚合“几何”期间发生 .NET Framework 错误:
System.FormatException:24141:输入的位置 13 处应有一个数字。输入有@data1。

4

1 回答 1

1

经过一番努力,我终于找到了解决这个问题的方法。如果其他人再次遇到此类问题,请发布解决方案。在几何中,当我通过@data1and时@data2,它的那些变量@data1只是不是它的浮点值。所以,我们可以做的是:

select @data1 =data1 from test1 where id=@Seedid  
select @data2 =data2 from test1 where id=@Seedid  
Set @POINTSTR = 'POINT(' + CAST(@data1 AS varchar(32)) + ' ' + CAST(@data2 AS varchar(32)) + ')';  
update test1  set data4 = geometry::STGeomFromText(@POINTSTR, 4326) where id=@Seedid;  
于 2013-02-12T18:02:14.057 回答