how to contain SHAPE.AREA into float var

740
2
07-31-2013 12:04 AM
HaniuHokkaido
New Contributor III
Dear experts,

I am trying to contain the value of SHAPE.AREA of a spatial view into a variable in t-sql. But I always encounter error "Error converting data type nvarchar to float."

Here is my query of the very last try before I am going mad:

declare myarea float
Exec OPT.sde.set_current_version 'sde.default'   
SET @FieldCursor = CURSOR FAST_FORWARD
FOR
SELECT  KEYID, case WHEN ISNUMERIC(sum(convert (float, ltrim(rtrim(AREA_HA)))))=1
     then cast ((sum(AREA_HA)) as float)*1
     --then convert(float,LTRIM(RTRIM(sum(AREA_HA))))
     else 0
     END as myarea
FROM         opt.sde.view_lu 
        GROUP BY KEYID HAVING KEYID=@keyid
OPEN @FieldCursor
FETCH NEXT FROM @FieldCursor
INTO @keyid,@myarea
WHILE @@FETCH_STATUS = 0


Pleas Help..

thanks

Haniu
0 Kudos
2 Replies
VinceAngelo
Esri Esteemed Contributor
The SHAPE.AREA field started as a DOUBLE value.  Your difficulty in transforming
into a numeric field probably has its root in how it came to be a wide string in
the first place.

- V
0 Kudos
HaniuHokkaido
New Contributor III
Hi Vince,

Thanks for the reply..

Today i just found out that the cause of the error is due to incorrect variable ordering (there are like 20 variables and this particular variable is in the middle. its hard to see). I move it to the correct place and the error is gone straight away.

😄

thanks for your attention
0 Kudos