views:

40

answers:

1

I have read some articles about using spatial optimized tables. Actually I use stored latitude and longitude as varchar comma-separated (lat;lng).

Could you suggest the best way to perform this change and enumerate the advantages. It's really necessary for a large project or only move to SQL Server 2008?

thanks.

A: 

I'd add two new persisted computed colunns to your table as illustrated in the demo below.

create table Demo (
    LatLng varchar(100),
    Lat as CAST(LEFT(LatLng, charindex(';',LatLng)-1) as float) PERSISTED,
    Lng as CAST(SUBSTRING(LatLng, charindex(';',LatLng)+1, LEN(LatLng)-charindex(';',LatLng)) as float) PERSISTED
)

insert into Demo
    (LatLng)
    values
    ('33.0000;15.222222')

select *
    from Demo

drop table Demo
Joe Stefanelli
I'm sorry, but that's well beyond the scope of a simple comment section here. I'd suggest that you continue to Google for some tutorials and examples. Then come back to SO with specific questions on anything that's still not clear for you.
Joe Stefanelli